r - Rearrange data for ANOVA -


i haven't quite got head around r , how rearrange data. have old spss data file needs rearranging can conduct anova in r.

my current data file has format:

one <- matrix(c(1, 2, 777.75, 609.30, 700.50, 623.45, 701.50, 629.95, 820.06, 651.95,"nofear","nofear"), nr=2,dimnames=list(c("1", "2"), c("subject","aayy", "bbyy", "aazz", "bbzz", "xx"))) 

and need rearrange this:

two <- matrix(c(1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 777.75, 701.5, 700.5, 820.06, 609.3, 629.95, 623.95, 651.95), nr=8, dimnames=list(c("1", "1", "1", "1", "2", "2", "2", "2"), c("subject","aa", "zz", "xx", "rt"))) 

i sure there easy way of doing it, rather hand coding. consideration.

this should it. can tweak bit, idea:

library(reshape) 3 <- melt(as.data.frame(one),id=c("subject","xx")) three$aa <- grepl("aa",three$variable) three$zz <- grepl("zz",three$variable) three$variable <- null  # cleanup three$xx <- as.factor(three$xx) three$aa <- as.numeric(three$aa) three$zz <- as.numeric(three$zz) 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -