Convert data frame common rows to columns

后端 未结 5 1394
时光取名叫无心
时光取名叫无心 2020-12-10 21:53

Say I have a data frame where one column is some repeating value (dates, IDs, etc). Is there a way to convert a data frame into a now data frame with columns instead of rep

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 21:59

    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, to = 50, by = 5), size = 30, replace = TRUE)
    d <- data.frame(a,b, c)
    #how to transpose it#
    e<-reshape(d,idvar='a',timevar='b',direction='wide')
    e
    

提交回复
热议问题