Replace values in data frame with other values according to a rule

前端 未结 4 1428
时光说笑
时光说笑 2020-12-16 15:19

I am an beginner in R and don`t find a solution for the following problem. Any help would be really appreciated!

I have a data.frame and want to replace certain valu

4条回答
  •  天命终不由人
    2020-12-16 15:59

    When you want to extract the year from the date, you can do this with the following line of code:

    dataframe$year <- substr(dataframe$date,1,4)
    

    When you want assign a class to the new variable simulataniously:

    dataframe$year <- as.integer(substr(dataframe$date,1,4))
    

提交回复
热议问题