[R] Subsetting a list
Patrick Connolly
p.connolly at hortresearch.co.nz
Fri Oct 21 02:26:08 CEST 2005
On Wed, 19-Oct-2005 at 05:09PM +0200, Martin Maechler wrote:
|> Lists can have 'dim' attributes and hence be treated as arrays;
|> Note that this is pretty rarely used and not too well supported
|> by some tools, one could say even 'print()' :
|>
|> > set.seed(0); L0 <- L <- lapply(rpois(12, lambda=3), seq); dim(L) <- 3:4; L
|> [,1] [,2] [,3] [,4]
|> [1,] Integer,5 Integer,3 Integer,5 Integer,3
|> [2,] Integer,2 Integer,5 Integer,6 1
|> [3,] Integer,2 Integer,2 Integer,4 Integer,2
for an occasion such as this, it can be clearer to do:
> transform(L)
X1 X2 X3 X4
1 1, 2, 3, 4, 5 1, 2, 3 1, 2, 3, 4, 5 1, 2, 3
2 1, 2 1, 2, 3, 4, 5 1, 2, 3, 4, 5, 6 1
3 1, 2 1, 2 1, 2, 3, 4 1, 2
best
--
Patrick Connolly
HortResearch
Mt Albert
Auckland
New Zealand
Ph: +64-9 815 4200 x 7188
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
I have the world`s largest collection of seashells. I keep it on all
the beaches of the world ... Perhaps you`ve seen it. ---Steven Wright
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
More information about the R-help
mailing list