Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
3 views
in R Programming by (4k points)
edited by

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?

1 Answer

0 votes
by (46k points)
edited by

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"

Hope this helps.

Related questions

+1 vote
1 answer
asked May 23, 2019 in R Programming by Nigam (4k points)
0 votes
1 answer
0 votes
1 answer
+2 votes
1 answer

Browse Categories

...