Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between [ ] and [[ ]] in R? [duplicate]

Tags:

r

  > levels(state.region)[2]
    [1] "S"
    > levels(state.region)[[2]]
    [1] "S"

They return the same value, so I don't know what is the difference between them.

like image 491
statistics_learning Avatar asked Nov 01 '15 13:11

statistics_learning


1 Answers

[] = always returns object of same class (out of basic object classes), can select more than one element of an object

[[]] = can extract one element from list or data frame, returned object (out of basic object classes) not necessarily list/dataframe

like image 57
sdayal Avatar answered Oct 04 '22 07:10

sdayal