To remove an element at a specific index from a list in R, you can use negative indexing.
In this example,
numbers
with numeric values.numbers <- c(1, 2, 3, 4, 5)
index_to_remove <- 3
numbers <- numbers[-index_to_remove]
print(paste("List after removing element at index", index_to_remove, ":", numbers))
List after removing element at index 3 : 1 2 4 5
In this example,
words
with string values.words <- c("apple", "banana", "cherry")
words <- words[-1]
print(paste("List after removing element at first index:", words))
List after removing element at first index: banana cherry
In this tutorial, we learned How to Remove Element at a Specific Index from a List in R language with well detailed examples.