Subtract a column in a dataframe from many columns in R

后端 未结 3 1178
闹比i
闹比i 2020-11-29 12:17

I have a dataframe. I\'d like to subtract the 2nd column from all other columns. I can do it in a loop, but I\'d like to do it in one call. Here\'s my working loop cod

3条回答
  •  無奈伤痛
    2020-11-29 12:44

    If you need to subtract the columns 3:ncol(df) from the second column

    df[3:ncol(df)] <- df[3:ncol(df)]-df[,2]
    

提交回复
热议问题