R Programming: Create a list of dataframes and access each of those dataframes from the list
R Programming: List Exercise-10 with Solution
Write a R program to create a list of dataframes and access each of those data frames from the list.
Sample Solution :
R Programming Code :
df1 = data.frame(y1 = c(0, 1, 2), y2 = c(3, 4, 5))
df2 = data.frame(y1 = c(6, 7, 8), y2 = c(9, 10, 11))
new_list = list(df1, df2)
print("New list:")
print(new_list)
print("Data frame-1")
print(new_list[[1]])
print("Data frame-2")
print(new_list[[2]])
Sample Output:
[1] "New list:" [[1]] y1 y2 1 0 3 2 1 4 3 2 5 [[2]] y1 y2 1 6 9 2 7 10 3 8 11 [1] "Data frame-1" y1 y2 1 0 3 2 1 4 3 2 5 [1] "Data frame-2" y1 y2 1 6 9 2 7 10 3 8 11
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a R program to convert a given list to vector.
Next: Write a R program to count number of objects in a given list.
Test your Programming skills with w3resource's quiz.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics