[R] Proper apply function for matrices embedded in lists
Bcampbell99
BrianD.Campbell at ec.gc.ca
Thu Apr 26 01:18:41 CEST 2012
Hi:
I have a small problem that I'm not quite sure how to figure out. I've
generated some randomized (permutated) data which consists of nrows=3 by
ncols=165 (see below) per element (3 x 165 = 495 sub-elements).
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
[,14].......
[1,] 0 0 0 0 0 0 0 0 0 0 0 0 0
0
[2,] 0 0 0 0 0 0 0 0 0 0 0 1 0
0
[3,] 0 0 0 0 0 0 0 0 0 0 0 1 0
1
[,159] [,160] [,161] [,162] [,163] [,164] [,165]
[1,] 0 0 0 1 0 0 9
[2,] 0 0 0 0 0 0 8
[3,] 0 0 0 2 0 0 9
I generated 1000 permutations of this structure which was then stored in a
list-like object (still actually called a matrix)
[,1] [,2] [,3] [,4] [,5] [,6]
.....[,1000]
[1,] Numeric,495 Numeric,495 Numeric,495 Numeric,495 Numeric,495
Numeric,495
[2,] Numeric,495 Numeric,495 Numeric,495 Numeric,495 Numeric,495
Numeric,495
[3,] Numeric,495 Numeric,495 Numeric,495 Numeric,495 Numeric,495
Numeric,495
[4,] Numeric,495 Numeric,495 Numeric,495 Numeric,495 Numeric,495
Numeric,495
[5,] Numeric,495 Numeric,495 Numeric,495 Numeric,495 Numeric,495
Numeric,495
[6,] Numeric,495 Numeric,495 Numeric,495 Numeric,495 Numeric,495
Numeric,495
[7,] Numeric,495 Numeric,495 Numeric,495 Numeric,495 Numeric,495
Numeric,495
[8,] Numeric,495 Numeric,495 Numeric,495 Numeric,495 Numeric,495
Numeric,495
[9,] Numeric,495 Numeric,495 Numeric,495 Numeric,495 Numeric,495
Numeric,495
Where [1,]...[2,]....[9,] represent sites (sampling units) and
[,1],[,2].....[,1000] represent permutations.
I'd like to take the column sums of from each matrix so instead of having a
r (3) x c (165) structure, I would get r(1) x (165) structure while
maintaining the [1,].....[,1000] design.
When I tried
apply(data[1,1],2,sum) for example, I got an error;
in apply(data[1,1], 2, sum) :
dim(X) must have a positive length
Anyone have a quick suggestion (I'm sure there is a simple solution out
there) how to do this (have I provided enough background information on the
problem?).
Most appreciatively:
Brian Campbell
--
View this message in context: http://r.789695.n4.nabble.com/Proper-apply-function-for-matrices-embedded-in-lists-tp4588386p4588386.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list