Re: [R] how to reshape the data.frame from long to wide in a specific order

2011-03-14 Thread Gabor Grothendieck
On Mon, Mar 14, 2011 at 9:06 PM, zhenjiang xu wrote: > Hi, > > For example, the data.frame like: > > origdata.long <- read.table(header=T, con <- textConnection(' >  subject sex condition measurement >       1   M   control         7.9 >       1   M     first        12.3 >       1   M    second  

Re: [R] how to reshape the data.frame from long to wide in a specific order

2011-03-14 Thread Jeff Newmiller
I just fix it afterward: dta <- dta[,c("col1","col2","col3")] --- Jeff Newmiller The . . Go Live... DCN: Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. wi

Re: [R] how to reshape the data.frame from long to wide in a specific order

2011-03-14 Thread David Winsemius
On Mar 14, 2011, at 10:24 PM, Henrique Dallazuanna wrote: Try this: reshape(origdata.long, direction = 'wide', timevar = 'condition', idvar = c('subject', 'sex')) If you first set the order in the desired sequence: origdata.long$condition <- factor(origdata.long$condition, levels=c('fi

Re: [R] how to reshape the data.frame from long to wide in a specific order

2011-03-14 Thread Henrique Dallazuanna
Try this: reshape(origdata.long, direction = 'wide', timevar = 'condition', idvar = c('subject', 'sex')) On Mon, Mar 14, 2011 at 10:06 PM, zhenjiang xu wrote: > Hi, > > For example, the data.frame like: > > origdata.long <- read.table(header=T, con <- textConnection(' > subject sex condition me

Re: [R] how to reshape the data.frame from long to wide in a specific order

2011-03-14 Thread Dennis Murphy
Hi: This is straightforward with the reshape package: library(reshape) origdata.long$condition <- factor(origdata.long$condition, levels = c('first', 'second', 'control')) cast(origdata.long, subject + sex ~ condition) Using measurement as value column. Use the value argument to cast to ove

[R] how to reshape the data.frame from long to wide in a specific order

2011-03-14 Thread zhenjiang xu
Hi, For example, the data.frame like: origdata.long <- read.table(header=T, con <- textConnection(' subject sex condition measurement 1 M control 7.9 1 M first12.3 1 Msecond10.7 2 F control 6.3 2 F first