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

前端 未结 4 1437
时光说笑
时光说笑 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:58

    You can use match:

    dataframe <- transform(dataframe, Year = year[match(date, yearend)])
    
          date variable value Year
    1 19921231        a     1 1992
    2 19931231        a     2 1993
    3 19941231        a     3 1994
    4 19941231        b     4 1994
    5 19931231        b     5 1993
    6 19941231        b     6 1994
    

提交回复
热议问题