I have the initial matrice:> *data.frame(Subject=rep(100:101, each=4), Quarter=rep(paste("Q",1:4,sep=""),2), Boolean = rep(c("Y","N"),4))* Subject Quarter Boolean 1 100 Q1 Y 2 100 Q2 N 3 100 Q3 Y 4 100 Q4 N 5 101 Q1 Y 6 101 Q2 N 7 101 Q3 Y 8 101 Q4 N ...>And I would like to group the Subject by Quarter using as a result in the table the value of the third variable (Boolean). The final result would give: Subjet Q1 Q2 Q3 Q4 1 100 Y Y Y Y 2 101 N N N N ...>I started using the *table(Subject, Quarter)* but can't find a way to correspond the Boolean information in the table.... Thanks in advance for the ideas... Pascal Candolfi [[alternative HTML version deleted]]
Hi, I think you should take a look to ?reshape. Regards Patricia> Date: Thu, 19 Feb 2009 11:02:58 +0100 > From: pcandolfi@gmail.com > To: r-help@r-project.org > Subject: [R] table with 3 varialbes > > I have the initial matrice: > > > *data.frame(Subject=rep(100:101, each=4), Quarter=rep(paste("Q",1:4, > sep=""),2), Boolean = rep(c("Y","N"),4))* > Subject Quarter Boolean > 1 100 Q1 Y > 2 100 Q2 N > 3 100 Q3 Y > 4 100 Q4 N > 5 101 Q1 Y > 6 101 Q2 N > 7 101 Q3 Y > 8 101 Q4 N > ... > > > > And I would like to group the Subject by Quarter using as a result in the > table the value of the third variable (Boolean). The final result would > give: > > Subjet Q1 Q2 Q3 Q4 > 1 100 Y Y Y Y > 2 101 N N N N > ... > > > > I started using the *table(Subject, Quarter)* but can't find a way to > correspond the Boolean information in the table.... > Thanks in advance for the ideas... > > Pascal Candolfi > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org 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._________________________________________________________________ [[elided Hotmail spam]] [[alternative HTML version deleted]]
Hi, Look, is simple with reshape: x <- data frame(...) reshape( x, idvar = "Subject", direction = "wide", timevar = "Quarter") Regards, Patricia> Date: Thu, 19 Feb 2009 11:02:58 +0100 > From: pcandolfi@gmail.com > To: r-help@r-project.org > Subject: [R] table with 3 varialbes > > I have the initial matrice: > > > *data.frame(Subject=rep(100:101, each=4), Quarter=rep(paste("Q",1:4, > sep=""),2), Boolean = rep(c("Y","N"),4))* > Subject Quarter Boolean > 1 100 Q1 Y > 2 100 Q2 N > 3 100 Q3 Y > 4 100 Q4 N > 5 101 Q1 Y > 6 101 Q2 N > 7 101 Q3 Y > 8 101 Q4 N > ... > > > > And I would like to group the Subject by Quarter using as a result in the > table the value of the third variable (Boolean). The final result would > give: > > Subjet Q1 Q2 Q3 Q4 > 1 100 Y Y Y Y > 2 101 N N N N > ... > > > > I started using the *table(Subject, Quarter)* but can't find a way to > correspond the Boolean information in the table.... > Thanks in advance for the ideas... > > Pascal Candolfi > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org 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._________________________________________________________________ [[elided Hotmail spam]] [[alternative HTML version deleted]]