add column with row wise mean over selected columns using dplyr

前端 未结 3 724
心在旅途
心在旅途 2020-12-21 00:49

I have a data frame which contains several variables which got measured at different time points (e.g., test1_tp1, test1_tp2, test1_tp3

3条回答
  •  生来不讨喜
    2020-12-21 01:02

    Not a dplyr solution, but you can try:

    cols_2sum <- grepl('test1',colnames(data))
    rowMeans(data[,cols_2sum])
    

提交回复
热议问题