Q:

Write a R program to select second element of a given nested list

0

Write a R program to select second element of a given nested list.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

x = list(list(0,2), list(3,4), list(5,6))
print("Original nested list:")
print(x)
e = lapply(x, '[[', 2)
print("Second element of the nested list:")
print(e)

Sample Output:

[1] "Original nested list:"
[[1]]
[[1]][[1]]
[1] 0

[[1]][[2]]
[1] 2


[[2]]
[[2]][[1]]
[1] 3

[[2]][[2]]
[1] 4


[[3]]
[[3]][[1]]
[1] 5

[[3]][[2]]
[1] 6


[1] "Second element of the nested list:"
[[1]]
[1] 2

[[2]]
[1] 4

[[3]]
[1] 6

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now