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" "Rainy"
[[1]][[2]]
[1] "Warm" "Cold"
[[1]][[3]]
[1] "Normal" "High"
[[1]][[4]]
[1] "Strong" "Weak"
[[1]][[5]]
[1] "Warm" "Cool"
[[1]][[6]]
[1] "Same" "Change"
[[2]]
[[2]][[1]]
[1] "Sunny" "Cloudy" "Rainy"
[[2]][[2]]
[1] "Warm" "Cold"
[[2]][[3]]
[1] "Normal" "High"
[[2]][[4]]
[1] "Strong" "Weak"
[[2]][[5]]
[1] "Warm" "Cool"
[[2]][[6]]
[1] "Same" "Change"
Can I remove a component like this: > myList = mylist[[-particularIndex]]? I want a result like this:
[[1]]
[[1]][[1]]
[1] "Sunny" "Cloudy" "Rainy"
[[1]][[2]]
[1] "Warm" "Cold"
[[1]][[3]]
[1] "Normal" "High"
[[1]][[4]]
[1] "Strong" "Weak"
[[1]][[5]]
[1] "Warm" "Cool"
[[1]][[6]]
[1] "Same" "Change"
I can’t make a string name label for that list. I have to reference rows by index(particular index) (using rownames(myList) to delete something won’t help me).
I think you came very close to the right answer:
The above works to get rid of the original second component. Note single square brackets, and compare with:
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