Number values include comma — how do I make these numeric? [duplicate]

青春壹個敷衍的年華 提交于 2019-12-01 03:34:36

If you are trying to add a new column var2 to df, you can use the following

  df$var2 <- as.numeric(gsub(",", "", as.character(df$var1)))

Use as.numeric(gsub(",", "", df$var1)).

You want to use gsub as sub will only replace the first comma.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!