How to read csv file in R where some values contain the percent symbol (%)

后端 未结 4 611
面向向阳花
面向向阳花 2020-11-30 14:18

Is there a clean/automatic way to convert CSV values formatted with as percents (with trailing % symbol) in R?

Here is some example dat

4条回答
  •  余生分开走
    2020-11-30 15:06

    This is the same as Roland's solution except using the stringr package. When working with strings I'd recommend it though as the interface is more intuitive.

    library(stringr)
    d <- str_replace(junk$percent.error, pattern="%", "")
    junk$percent.error <- as.numeric(d)/100
    

提交回复
热议问题