r - Convert data frame common rows to columns -
say have info frame 1 column repeating value (dates, ids, etc). there way convert info frame info frame columns instead of replicating rows? want transpose this:
col1 col2 col3 1 aa 30 2 aa 40 3 aa 10 1 bb 20 2 bb 12 3 bb 15 1 cc 40 2 cc 31 3 cc 12
into this:
aa bb cc 1 30 20 40 2 40 12 31 3 10 15 12
here code makes sample of first info frame:
a <- c(rep(1:10, 3)) b <- c(rep("aa", 10), rep("bb", 10), rep("cc", 10)) set.seed(123) c <- sample(seq(from = 20, = 50, = 5), size = 30, replace = true) d <- data.frame(a,b, c)
i unsure how transpose it.
a <- c(rep(1:10, 3)) b <- c(rep("aa", 10), rep("bb", 10), rep("cc", 10)) set.seed(123) c <- sample(seq(from = 20, = 50, = 5), size = 30, replace = true) d <- data.frame(a,b, c) #how transpose it# e<-reshape(d,idvar='a',timevar='b',direction='wide') e
r reshape
No comments:
Post a Comment