代码之家  ›  专栏  ›  技术社区  ›  Tim Wilcox

如何在R中修改数据帧中的现有值

  •  0
  • Tim Wilcox  · 技术社区  · 4 年前

     year  month  area     employment
     2020   09    000001      105
     2020   10    000001      105
     2020   09    123444      108
     2020   09    123444      109
    

      year  month  area     employment
     2020   09    000003      105
     2020   10    000003      105
     2020   09    123400      108
     2020   09    123400      109
    

    原因是每个区域有两行数据,但有些区域有两个名称。000001和000003相同。在SQL中,您会使用update,然后设置area='000003',其中。。。。。

    1 回复  |  直到 4 年前
        1
  •  1
  •   sjillani    4 年前

    以下代码应该有效:

    
    df$area[df$area==000001]<-000003
    df$area[df$area== 123444]<-123400
    
    

    其中df是您的数据帧。