Wednesday, October 2, 2013

Reshape data in R



hsb2 <- br="" faq="" header="T," hsb2.csv="" http:="" r="" read.table="" sep="," stat="" www.ats.ucla.edu="">hsb2[1:10,]
l <- br="" hsb2="" reshape="">  varying = c("read", "write", "math", "science", "socst"),
  v.names = "score",
  timevar = "subj",
  times = c("read", "write", "math", "science", "socst"),
  new.row.names = 1:1000,
  direction = "long")

l[1:10,]
 
l.sort <- br="" id="" l="" order=""> 
l.sort[1:10,]

l.sort

w <- br="" l.sort="" reshape="">  timevar = "subj",
  idvar = c("id", "female", "race", "ses", "schtyp", "prog"),
  direction = "wide")
 
w

w[1:10,]