How to add a factor column to dataframe based on a conditional statement from another column?

后端 未结 1 893
轮回少年
轮回少年 2020-11-30 05:38

I have a dataframe for which I need to add a factor column based on a conditional statement. Here is the data.

Code:

    morstats.agri.f <- morocc         


        
相关标签:
1条回答
  • 2020-11-30 06:28

    you can use ifelse like this

    dataframe$periodframe <- ifelse(dataframe$year > 1991,"post-1991", "pre-1991")
    
    0 讨论(0)
提交回复
热议问题