Update subset of values in a dataframe column

前端 未结 1 1604
滥情空心
滥情空心 2020-12-06 15:41

Here\'s an excerpt of my dataframe:

  x         y     se
  4         a     7.146329
 15         a     8.458633
 17         a     9.286849
 11         b     6         


        
相关标签:
1条回答
  • 2020-12-06 15:54

    Could use ifelse here. Assuming data frame is named df1:

    df1$x <- ifelse(df1$y %in% c("a", "b"), df1$x - 1, df1$x)
    
    0 讨论(0)
提交回复
热议问题