[R] neater way to create data frame?

Louize Hill louize99 at yahoo.co.uk
Mon Nov 8 23:58:04 CET 2004


Hello,

I have a large data frame and am aiming to create a summary data frame in
order to plot quarterly means by age. However, it seems as though I am
taking a very long winded approach to this - can anybody point me in the
direction of something neater?

#original table is dat2,
dat5<- tapply (dat2$col1, INDEX=list(dat2$Age, dat2$Quarter), FUN=mean)

dat5 <- data.frame(dat5)
names(dat5) <- c("qt1", "qt2", "qt3", "qt4")
dat6 <- data.frame(age=row.names(dat5), dat5)
#transform rownames / 1st column from factor to variables
dat7 <- as.numeric (as.character(dat6$age))
#create new table with 5 columns
dat8 <- cbind (dat7, dat6$qt1, dat6$qt2, dat6$qt3, dat6$qt4)
#still need to add column names to this new table...

I am using R2.0.0 on W2K.
Thanks
Louize




More information about the R-help mailing list