R Programming: Create a list containing a vector, a matrix and a list and remove the second element
R Programming: List Exercise-6 with Solution
Write a R program to create a list containing a vector, a matrix and a list and remove the second element.
Sample Solution :
R Programming Code :
list_data <- list(c("Red","Green","Black"), matrix(c(1,3,5,7,9,11), nrow = 2),
list("Python", "PHP", "Java"))
print("List:")
print(list_data)
print("Remove the second element of the list:")
list_data[2] = NULL
print("New list:")
print(list_data)
Sample Output:
[1] "List:" [[1]] [1] "Red" "Green" "Black" [[2]] [,1] [,2] [,3] [1,] 1 5 9 [2,] 3 7 11 [[3]] [[3]][[1]] [1] "Python" [[3]][[2]] [1] "PHP" [[3]][[3]] [1] "Java" [1] "Remove the second element of the list:" [1] "New list:" [[1]] [1] "Red" "Green" "Black" [[2]] [[2]][[1]] [1] "Python" [[2]][[2]] [1] "PHP" [[2]][[3]] [1] "Java"
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a R program to select second element of a given nested list.
Next: Write a R program to create a list containing a vector, a matrix and a list and update the last element.
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