What is the difference between and notations to access the elements of a list or dataframe in R

0 votes

As R provides two different ways to access the elements of a list or a data.frame, what is the difference between both of them?

In which situations should I use[] over [[]]?

Apr 12, 2018 in Data Analytics by nirvana
• 3,130 points
2,987 views

1 answer to this question.

0 votes

R provides 3 basic indexing operators. Refer below for the syntax and example:

    a[i]
    a[i, j]
    a[[i]]
    a[[i, j]]
    a$x
    a$"x"

When it comes to vectors and matrices [[ are hardly used even though they have semantic differences from [.

While indexing multi-dimensional structures with a single index, a[[i]] or a[i] will return the ith sequential element of a.

When you use lists, [[ is used to select any single element, and [ is used to return a list of the selected elements.

[[ allows a single element to be selected using various indices like integer/character and [ indexes by vectors.

answered Apr 12, 2018 by kappa3010
• 2,090 points

Related Questions In Data Analytics

0 votes
1 answer

What is the difference between list and vector in R?

The difference are - A list holds different ...READ MORE

answered Oct 29, 2019 in Data Analytics by Cherukuri
• 33,030 points
48,236 views
0 votes
1 answer

What is the difference between library () and require () functions in R ?

 library() require() Library () function gives an error message ...READ MORE

answered Sep 5, 2018 in Data Analytics by zombie
• 3,790 points
2,668 views
0 votes
2 answers

What is the difference between %% and % in R programming?

HI, %% returns remainder in case of numeric ...READ MORE

answered Aug 26, 2019 in Data Analytics by anonymous
• 33,030 points
2,447 views
0 votes
1 answer

What is the difference between merge and bind in R?

Merge function merges an arbitrarily large series ...READ MORE

answered Oct 29, 2019 in Data Analytics by Cherukuri
• 33,030 points
7,632 views
+1 vote
1 answer

How to convert a list of vectors with various length into a Data.Frame?

We can easily use this command as.data.frame(lapply(d1, "length< ...READ MORE

answered Apr 4, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,711 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,399 views
0 votes
1 answer

How to convert a list to data frame in R?

Let's assume your list of lists is ...READ MORE

answered Apr 12, 2018 in Data Analytics by nirvana
• 3,130 points

edited Apr 12, 2018 by nirvana 22,138 views
+1 vote
1 answer

How to convert a list of dataframes in to a single dataframe using R?

You can use the plyr function: data <- ...READ MORE

answered Apr 14, 2018 in Data Analytics by Sahiti
• 6,370 points
7,106 views
0 votes
1 answer

How to limit output of a dataframe in R?

For randomly sampling a row/cell where a ...READ MORE

answered Apr 18, 2018 in Data Analytics by kappa3010
• 2,090 points
3,451 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP