I am trying to remove a component from list in R, but it is not working.
I have list like this:
> myList
[[1]]
[[1]][[1]]
[1] \"Sunny\" \"Cloudy\" \"
I think you came very close to the right answer:
> x <- list(list(1:3, 4:6), list(4:7, 2:3), list(4:6,1:2))
> x[-2]
[[1]]
[[1]][[1]]
[1] 1 2 3
[[1]][[2]]
[1] 4 5 6
[[2]]
[[2]][[1]]
[1] 4 5 6
[[2]][[2]]
[1] 1 2
The above works to get rid of the original second component. Note single square brackets, and compare with:
x[[-2]]
Error in x[[-2]] : attempt to select more than one element
Double squrare brackets do not work. (Actually that does work if there are only two compoennts in the list, but do not depend on that.)
There are numerous places that explain single versus double square brackets. One of them is Circle 8.1.54 of 'The R Inferno' http://www.burns-stat.com/pages/Tutor/R_inferno.pdf