Difference between [[1]] and [1] in R Programming

0 votes
What is the difference between [[1]] and [1] in R? When to use [[ ]] and [ ] in a list?
Jun 28, 2019 in Data Analytics by latha
250 views

1 answer to this question.

0 votes

Hey Latha,

The difference between them is that [[ ]]  is used to access a component in a list or matrix whereas [ ] is used to access a single element in a matrix or array.

Let me explain with an example of the same.

I created a list, matrix to create a new list consisting of a few numbers, list, matrix.

Now ill access elements using [[ ]] and [ ] below.

In the above image list1[[4]] and list1[4] would fetch the same element, but when you want to get a single element of a list part then [ ] is used like above.

A whole matrix can be accessed using [[]] or [] in a whole but to access sub-elements in a list member, we use [ ] such as an element in a matrix within a list as above.

answered Jun 28, 2019 by anonymous
• 32,440 points

Related Questions In Data Analytics

0 votes
1 answer

Difference between factor and as.factor in R programming

Hey @Ali, as.factor is a wrapper for ...READ MORE

answered Oct 29, 2018 in Data Analytics by Maverick
• 10,800 points
1,236 views
0 votes
1 answer

Difference between list(1:5) and list(1,2 ...5) in R.

It's very simple. list(1:4) creates a single element(vector) whereas ...READ MORE

answered Oct 14, 2019 in Data Analytics by rajeev
53 views
0 votes
1 answer
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,750 points
188 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

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

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

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

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,720 points
107 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
146 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
• 32,440 points
127 views
0 votes
1 answer

Difference between List(list1,list2) and c(list1,list2) in R

Hi Deepa, It's quite simple, let me explain ...READ MORE

answered Jun 26, 2019 in Data Analytics by Cherukuri
• 32,440 points
216 views