+1 vote
2 views
in R Programming by (4.1k 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 (46.1k 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 (4.1k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...