r - Reshaping block in data.frame to lists is columns uneven length -
i need r cast data:
status score job.id 1 status1 99 job1 2 status1 99 job2 3 status1 99 job3 4 status1 99 job4 5 status2 36 job5 6 status2 36 job6 7 status2 49 job7 8 status2 58 job8 9 status2 64 job9
to wide form:
status1 status2 1 job1 job6 2 job2 job7 3 job3 job8 4 job4 job9 5 job5 <na>
i not need compute value, need make lists. ideally score used sort resulting lists. columns length uneven. unable find elegant answer elsewhere. thank you.
if want them in single data frame, this:
library(reshape2) library(plyr) dat <- read.table(text = " status score job.id 1 status1 99 job1 2 status1 99 job2 3 status1 99 job3 4 status1 99 job4 5 status2 36 job5 6 status2 36 job6 7 status2 49 job7 8 status2 58 job8 9 status2 64 job9",header = true,sep = "") > dat <- ddply(dat,.(status),transform,ind = seq_along(status)) > dcast(dat,ind~status,fill = na,value.var = "job.id") ind status1 status2 1 1 job1 job5 2 2 job2 job6 3 3 job3 job7 4 4 job4 job8 5 5 <na> job9
Comments
Post a Comment