How do I change contents of a column in data.frame

I’m using data from World Development Indicators (WDI) and want to merge this data with some other data. My problem is that the spelling of country names in the two datasets is different. How do I change the country variable? library('WDI') df <- WDI(country="all", indicator= c("NY.GDP.MKTP.CD", "EN.ATM.CO2E.KD.GD", 'SE.TER.ENRR'), start=1998, end=2011, extra=FALSE) head(df) country iso2c year NY.GDP.MKTP.CD EN.ATM.CO2E.KD.GD SE.TER.ENRR 99 ArabWorld 1A 1998 575369488074 1.365953 NA 100 ArabWorld 1A 1999 627550544566 1.355583 19.54259 101 ArabWorld 1A 2000 723111925659 1.476619 NA 102 ArabWorld 1A 2001 703688747656 1.412750 NA 103 ArabWorld 1A 2002 713021728054 1.413733 NA 104 ArabWorld 1A 2003 803017236111 1.469197 NA How do i change ArabWorld to Arab World? There are a lot of names I need to change so doing this with the use of row.numbers will not give me enough flexibility. I want something that is similar to the `replace` function in Stata.
What country is Arab World? You might find the function recode in the car package useful, or changing this to a factor rather than a character vector and then modifying the levels. Other than that look at ?sub for replacement in character vectors.

以上就是How do I change contents of a column in data.frame的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准