Complicated reshaping

后端 未结 8 1475
南方客
南方客 2020-12-25 14:01

I want to reshape my dataframe from long to wide format and I loose some data that I\'d like to keep. For the following example:

df <- data.frame(Par1 =          


        
8条回答
  •  一个人的身影
    2020-12-25 14:53

    One Step solution combining reshape::cast with plyr::ddply

    cast(Par1 + Par2 + ParD ~ Type, data = ddply(df, .(Par1, Par2), transform, 
      ParD = paste(ParD, collapse = "_")), fun  = c(mean, length))
    

    NOTE that the dcast function in reshape2 does not allow multiple aggregate functions to be passed, while the cast function in reshape does.

提交回复
热议问题