[R] Confused about appending to list behavior...
Jason Rupert
jasonkrupert at yahoo.com
Fri Feb 19 13:48:10 CET 2010
Through help from the list and a little trial and error (mainly error) I think I figured out a couple of ways to append to a list. Now I am trying to access the data that I appended to the list. The example below shows where I'm trying to access that information via two different methods. It turns out that trying to access the data the way one would elements in a data.frame does not work. However, using the standard way of accessing data from a list, a la [[...]], seems to provide an answer.
By any chance is there more documentation out there on lists and this behavior, as I would like to try to better understand what is really going on and why one approach works and another doesn't.
Thank you again for all the help and feedback, as I love lists and especially the fact (that unlike data.frames) you can store different "type" data and also arrays of different lengths. They are great.
> example_list<-list(tracking<-c("house"), house_type<-c("brick", "wood"), sizes<-c(1600, 1800, 2000, 2400))
> example_list
[[1]]
[1] "house"
[[2]]
[1] "brick" "wood"
[[3]]
[1] 1600 1800 2000 2400
>
> cost_limits<-c(200000.25, 350010.15)
>
> example_list[[4]]<-cost_limits
>
> example_list
[[1]]
[1] "house"
[[2]]
[1] "brick" "wood"
[[3]]
[1] 1600 1800 2000 2400
[[4]]
[1] 200000.2 350010.2
> c(example_list,list(CostStuff=cost_limits))
[[1]]
[1] "house"
[[2]]
[1] "brick" "wood"
[[3]]
[1] 1600 1800 2000 2400
[[4]]
[1] 200000.2 350010.2
$CostStuff
[1] 200000.2 350010.2
> example_list$CostStuff
NULL
> example_list[[5]]
Error in example_list[[5]] : subscript out of bounds
> example_list[[4]]
[1] 200000.2 350010.2
More information about the R-help
mailing list