removing particular character in a column in r

我是研究僧i 提交于 2019-11-28 12:49:09

Items that appear to be character when printed but for which R thinks otherwise are generally factor classes objects. I'm also guessing htat you are not going to be happy with the list output that strsplit will return Try:

gsub( "%", "", as.character(LOAN$RATE) n)

Factors which are appear numeric can be a source of confusion as well:

> factor("14.9%")
[1] 14.9%
Levels: 14.9%
> as.character(factor("14.9%"))
[1] "14.9%"
> gsub("%", "", as.character(factor("14.9%")) )
[1] "14.9"

This is especially confusing since print.data.frame removes hte quotes:

> data.frame(z=factor("14.9%"), zz=factor(14.9))
      z   zz
1 14.9% 14.9

LOAN$RATE <- sapply(LOAN$RATE, function(x), gsub("%", "", x))

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