[R] table with a weight variable?

Marc Schwartz marc_schwartz at comcast.net
Thu Oct 4 00:00:57 CEST 2007


On Wed, 2007-10-03 at 21:31 +0000, lamack lamack wrote:
> Dear all, there is an R function do a frequency table considering a weight variable?
>  
> M A 23
> M B 34
> F A 23
> F B 45
>  
> I would like a table like this
>  
>       A       B
> M   23     34
> F   23      45

See ?xtabs

For example, given a data frame 'DF':

> DF
  V1 V2 V3
1  M  A 23
2  M  B 34
3  F  A 23
4  F  B 45


> xtabs(V3 ~ V1 + V2, DF)
   V2
V1   A  B
  F 23 45
  M 23 34

HTH,

Marc Schwartz



More information about the R-help mailing list