Adding new column with conditional values using ifelse

前端 未结 3 1244
刺人心
刺人心 2020-12-10 10:06

I have a data frame with more than 400.000 observations and I\'m trying to add a column to it which its values depend on another column and sometimes multiple ones.

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 10:16

    Same idea but assign it like this instead. No package needed.

    M$Size <- ifelse(M$Number <= 50, 'Small', ifelse(M$Number <= 70, 'Medium', 'Big'))
    

    Result:

      Letter Number   Size
    1      A      5  Small
    2      B    100    Big
    3      C     60 Medium
    

提交回复
热议问题