Write a R program to select second element of a given nested list.
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
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer