Back
There are two different methods for accessing the element of a list or data frame- [ ] and [[ ]] , what is the difference between them?
When should I use one over the other and what’s the difference between them?
The main difference between these two are, mainly Double brackets accesses a list element whereas a single element gives back a list with a single element.
E.x.
lst <- list('one','two','three') q <- lst[1] class(q) ## returns "list" q <- lst[[1]] class(q) ## returns "character"
lst <- list('one','two','three')
q <- lst[1]
class(q)
## returns "list"
q <- lst[[1]]
## returns "character"
Hope this helps.
31k questions
32.8k answers
501 comments
693 users