I have a list like that
[[1]]
[1] a1 b1 c1
[[2]]
[1] a2 b2 c2
[[3]]
[1] a3 b3 c3
I want specific element removed from each part of it:
[[1]]
[1] a1 c1
[[2]]
[1] a2 c2
[[3]]
[1] a3 c3
I tried tail
but removes "outer" elements. Maybe some indexing would do?
The pop() method is one of the list object method used to remove an element from the list and returns it. While using the pop() method, you have to specify the index value of the element in the list as an argument and return the popped out element as the desired output.
To delete an item at specific index from R Vector, pass the negated index as a vector in square brackets after the vector.
Declare a boolean vector that has TRUE at all the positions you want to retain and FALSE at those you want to delete. Suppose that vector is y. Then, x[y] will give you the requires output.
Assuming the pattern is just that you want the second element removed,
lapply(List, function(x) x[-2])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With