Replacing commas and dots in R

前端 未结 3 1359
名媛妹妹
名媛妹妹 2020-12-28 17:25

I have a whole column of numbers that include dot separators at the thousands and comma instead of dot as an dismal separator. When I try to create a numeric column out of t

3条回答
  •  既然无缘
    2020-12-28 18:03

    You need to escape the "." in your regular expression, and you need to replace the commas with a "." before you can convert to numeric.

    > as.numeric(gsub(",", ".", gsub("\\.", "", var1)))
    [1]   50   72  960 1920   50   50  960
    

提交回复
热议问题