If the factor have only level:
apply(m1, 2, tapply, addNA(part2), mean)[-2,,drop = FALSE]
On Tue, Mar 16, 2010 at 12:43 PM, Christophe Genolini
wrote:
> As I told you in private, thanks, it works perfectly.
>
> More precisely, I am working with 3D array. Your code works well (both on
> matrix o
As I told you in private, thanks, it works perfectly.
More precisely, I am working with 3D array. Your code works well (both
on matrix or on array).
But when part is a factor with only one value, the result has not a
correct dimension (vector if m is a matrix, a matrix if m is an array).
Any way
Try this:
apply(m, 2, tapply, part, mean)
On Mon, Mar 15, 2010 at 2:10 PM, Christophe Genolini
wrote:
> Hi the list,
>
> As it is say in its doc, the aggregate function remove empty subsets. Is it
> possible to NOT remove empty subset ?
> --- 8< ---
> m <- matrix(1:12,4)
> part <- factor(c("
Hi the list,
As it is say in its doc, the aggregate function remove empty subsets. Is
it possible to NOT remove empty subset ?
--- 8< ---
m <- matrix(1:12,4)
part <- factor(c("A","B","A","B"),levels=c("A","B","C"))
aggregate(m,list(part),mean)
### I get:
# Group.1 V1 V2 V3
# 1 A 2
4 matches
Mail list logo