Modify values in a column subject to condition?

后端 未结 2 900
小鲜肉
小鲜肉 2021-01-21 12:21

I know that this is a very silly question but I cannot work out how to do it. I want to subtract 300 from the values on each row on the trial1 column if they are larger than 29

2条回答
  •  后悔当初
    2021-01-21 13:04

    Your first attempt was close but there is no -= operator in base R, so you need to supply the subset on the right hand side as well.

    sums[sums$trial1 > 299,"trial1"] <- sums[sums$trial1 > 299,"trial1"]-300
    

提交回复
热议问题