How can I make a list of lists in R

0 votes
In R, I'm not sure how to build a list of lists. I have a number of lists that I'd like to combine into a single data structure to make accessing them easier. However, it appears that in R, you cannot utilise a list of lists, thus if I acquire list l1 from another list, say, l2, I won't be able to access the components of l1. How can I put it into practise?

EDIT: Here's an example of something that doesn't work for me:

list1 is a list of a list of a list of a list of ()

1 in list1[1]

2 in list1[2]

list2 - a list of a list of a list of a list ()

'a' in list2[1]

'b' in list2[2]

list all - a list of everything (list1, list2)

a = list all[1] a = list all[1] a = list all[

a[2]

#[[1]]

#NULL

However, it should be a list!
Jun 19, 2022 in Data Analytics by Avinash
• 1,260 points
636 views

1 answer to this question.

0 votes
Lists of lists are simple to create.

list1 = list(a = 2, b = 3).
list2 – list(c = "a," d = "b"
list in mylist (list1, list2)
There are now two lists within of mylist. You can use mylist[[1]] to get list1. You must do the following actions if you want to be able to use anything like mylist$list1.

list in mylist

Lists 1 and 2 are equal to one other. As of right now, you can
mylist$list1
To comment on your edit. simply index using double brackets

list all[[1]] a
a[[1]]
#[1] 1 a[[2]]
#[1] 2
answered Jun 24, 2022 by Sohail
• 3,040 points

Related Questions In Data Analytics

0 votes
1 answer

How do I make a matrix from a list of vectors in R?

Suppose l1 and l2 are my vectors, li = ...READ MORE

answered Aug 7, 2019 in Data Analytics by Cherukuri
• 33,030 points
1,318 views
0 votes
1 answer

How to create dummy variables based on a categorical variable of lists in R?

You can use mtabulate in the following way: library(qdapTools) cbind(data[1], ...READ MORE

answered Apr 13, 2018 in Data Analytics by CodingByHeart77
• 3,750 points
2,653 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,100 views
0 votes
1 answer

How can I delete multiple values from a vector in R?

The %in% operator tells  which elements are ...READ MORE

answered Apr 27, 2018 in Data Analytics by shams
• 3,670 points
6,204 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,570 points
1,047 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
1,225 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
5,910 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
1,157 views
0 votes
1 answer

How can I create a correlation matrix in R?

An example, d <- data.frame(x1=rnorm(10), ...READ MORE

answered Jun 14, 2022 in Data Analytics by Sohail
• 3,040 points
528 views
0 votes
1 answer

Use of $ and %% operators in R

According to help('percent in percent'), percent in ...READ MORE

answered Jun 23, 2022 in Data Analytics by Sohail
• 3,040 points
772 views
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