[R] Creating a table

Michael Graber michael_graber at gmx.de
Tue Nov 14 21:20:38 CET 2006


Dear R List,

I am a new to R,  so my question may be easy to answer for you:

I have a dataframe, for example:

df<-data.frame(loc=c("A","B","A","A","A"), 
year=as.numeric(c("1970","1970","1970","1976","1980")))

and I want to create the following table without using loops:

      1970-74 ; 1975-79 ; 1980-85; rowsum
A         2               1               1          4
B         1               0                0          1
colsum   3                1               1        5

so that the frequencies of df$loc are shown in the table for different 
time intervals.

Thanks in advance for any hint,

Michael Graber



More information about the R-help mailing list