[R] ave gives unexpected NA's

Wolfram Fischer wolfram at fischer-zim.ch
Fri Oct 22 15:46:19 CEST 2004


[R 2.0.0 on Linux]

I tried:
> df <- data.frame(
     grp1=factor( c('A' ,'A' ,'A' ,'D', 'D' ) ) ,
     grp2=factor( c('a1','a2','a2','d1','d1') )
     )
> df
  grp1 grp2 val
1    A   a1   1
2    A   a2   2
3    A   a2   4
4    D   d1   8
5    D   d1  16

I got:
> with( df, ave( val, grp1, grp2, FUN=sum ) )
[1]  1 24 24 NA NA

I have expected to get:
[1]  1 6 24

Do I misunderstand something with `ave' or is there a bug?

Thanks - Wolfram




More information about the R-help mailing list