[R] list of lists question
Karla Sartor
ksartor at montana.edu
Wed Nov 24 03:43:30 CET 2004
Hello all,
As a general programming question I can't seem to figure out how to make
a list of lists in R.
As matrices won't work as they have to be rectangular.
I am sure that there is an easy solution but...
the specific situation is this:
- I have created a Tukey confidence interval table and have listed the
means that are not significantly different
- then using these not significantly different pairs I have created the
groups of means that are not significantly different from each other
the issue then is that many of these lists are subsets of other lists
and I need to check for this.
Below is a little program is illustrate the issue
> a=c(1,1,1,1,1) # generate the first list
> b=c(2,2,2) # generate a second list
> c=c(a,b) #combine them
> cat(c, "\n") # and print
1 1 1 1 1 2 2 2 # this is 1-D!!! ahh
> d=list(a,b) # make a list of a and b
> d # and print
[[1]] #this is exactly what I want,
but continue
[1] 1 1 1 1 1
[[2]]
[1] 2 2 2
> e=list(d,a) # now on the next iteration I
need to add another list to this list of lists
> e # and print
[[1]] # ahh all hell has broken
loose and this is not what I want
[[1]][[1]] # desired result below
[1] 1 1 1 1 1
[[1]][[2]]
[1] 2 2 2
[[2]]
[1] 1 1 1 1 1
-------------
desired result
#wrong code but this is what I want to happen
a=c(1,1,1,1,1,1,1)
for(i in 1:5) {
a=list(a,1:5)
}
output I want is (something like)
[1] 1 1 1 1 1 1 1
[2] 1 2 3 4 5
[3] 1 2 3 4 5
[4] 1 2 3 4 5
[5] 1 2 3 4 5
[6] 1 2 3 4 5
so then I could call cat(a[1]) and get 1 1 1 1 1 1 1 1 and cat(a[2]) and
get 1 2 3 4 5
Anyone know the answer (hopefully simple)
Cheers,
Karla Sartor
----------------------------------------------------------
Karla Sartor
Montana State University - LRES
ksartor at montana.edu
More information about the R-help
mailing list