[R] tabulating 2 factors weighting by a third var

Luca Meyer lucam1968 at gmail.com
Mon Dec 20 07:07:35 CET 2010


This must be an easy one but so far I haven't find a way out...

I have a data frame such as:

$ v1    : Factor w/ 5 levels
$ v2    : Factor w/ 2 levels
$ v3    : Class 'difftime'  atomic [1:6666]

basically v1 and v2 are factors, while v3 is a variable containing the duration of certain activities (values ranging from 11 to 45000 sec, no missing values)

How can I get a table such that v1 levels will show as rows, v2 levels as columns and v3 is the weight by which table(v1,v2) is weighted? That is, instead of getting the count of occurences in each of the 10 cells of table(v1,v2) I would like to get the sum(v3), how can it be done?


Luca Meyer
IBM SPSS Statistics release 19.0.0
R version 2.12.1 (2010-12-16)
Mac OS X 10.6.5 (10H574) - kernel Darwin 10.5.0

More information about the R-help mailing list