How do add a column in a data frame in R

后端 未结 5 997
逝去的感伤
逝去的感伤 2020-12-15 12:58

I have imported data from a file into a data frame in R. It is something like this.

Name      Count   Category
A         100     Cat1
C         10      Cat2
         


        
5条回答
  •  生来不讨喜
    2020-12-15 13:49

    You can use ifelse. If your data frame were called df you would do:

    df$cat <- ifelse(df$name<100, "Ones", "Hundreds")
    df$cat <- ifelse(df$name<1000, df$cat, "Thousands")
    

提交回复
热议问题