Merge multiple variables in R

前端 未结 6 1735
闹比i
闹比i 2020-12-04 01:06

I have a dataset such that the same variable is contained in difference columns for each subject. I want to merge them to the same columns.

E.g.:, I have this dataf

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 01:25

    The base transform will do this:

    d <- transform(d, 
                   DV1 = rowSums(d[c("DV1_A", "DV1_B", "DV1_C")], na.rm=T),
                   DV2 = rowSums(d[c("DV2_A", "DV2_B", "DV2_C")], na.rm=T)
              )
    

提交回复
热议问题