Wednesday 15 June 2011

What is the difference between dataset[,'column'] and dataset$column in R? -



What is the difference between dataset[,'column'] and dataset$column in R? -

if want list rows of column in dataset in r, able in these 2 ways:

> dataset[,'column'] > dataset$column

it appears both give me same result. difference?

in practice, not much, long dataset info frame. main difference dataset[, "column"] formulation accepts variable arguments, j <- "column"; dataset[, j] while dataset$j instead homecoming column named j, not want.

dataset$column list syntax , dataset[ , "column"] matrix syntax. info frames lists, each list element column , every element has same length. why length(dataset) returns number of columns. because "rectangular," able treat them matrices, , r kindly allows utilize matrix syntax on info frames.

note that, lists, list$item , list[["item"]] synonymous. again, biggest difference latter form evaluates argument, whereas former not. true in form `$`(list, item), equivalent list$item. in hadley wickham's terminology, $ uses "non-standard evaluation."

also, mentioned in comments, $ uses partial name matching, [[ not default (but has alternative utilize partial matching), , [ not allow @ all.

i recently answered similar question additional details might involvement you.

r

No comments:

Post a Comment