To expand on what Sarah and Michael said:
if you have a 3d array:
> x<-array(1:4,c(2,2,4))
> x
, , 1
[,1] [,2]
[1,]13
[2,]24
, , 2
[,1] [,2]
[1,]13
[2,]24
, , 3
[,1] [,2]
[1,]13
[2,]24
, , 4
[,1] [,2]
[1,]13
[2,]
Hi,
On Wed, Nov 16, 2011 at 3:13 PM, wrote:
>
> I have the following scenario:
>
>> m <- matrix(1:4, ncol=2)
>> m
> [,1] [,2]
> [1,] 1 3
> [2,] 2 4
>> apply(m, 2, sum)
> [1] 3 7
>> apply(m, 1, sum)
> [1] 4 6
>
> So I can apply to rows *or* columns. According to the documentation
It's the same as what you began with -- and that's because you broke
it down by columns and rows and took the sum of everything that
resulted.
I.e.,
sum(m[1,1])
sum(m[2,1])
sum(m[1,2])
sum(m[2,2])
and put them back together.
Michael
On Wed, Nov 16, 2011 at 3:13 PM, wrote:
>
> I have the fol
I have the following scenario:
> m <- matrix(1:4, ncol=2)
> m
[,1] [,2]
[1,]13
[2,]24
> apply(m, 2, sum)
[1] 3 7
> apply(m, 1, sum)
[1] 4 6
So I can apply to rows *or* columns. According to the documentation
(?apply)
MARGIN a vector giving the subscripts which the functio
4 matches
Mail list logo