Michael One solution:
df<-data.frame(loc=c("A","B","A","A","A"), year=c(1970,1970,1970,1976,1980)) df[,3] <- cut(df$year, c(1969.5,1974.5,1979.5,1984.5), c('1970-74','1975-79','1980-85')) with(df, addmargins(table(loc, V3))) Peter Alspach > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Michael Graber > Sent: Wednesday, 15 November 2006 9:21 a.m. > To: R-Mailingliste > Subject: [R] Creating a table > > 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 > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________________ The contents of this e-mail are privileged and/or confidenti...{{dropped}} ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.