removing particular character in a column in r

后端 未结 3 389
不思量自难忘°
不思量自难忘° 2020-12-06 07:01

I have a table called LOAN containing column named RATE in which the observations are given in percentage for example 14.49% how can i format the table so that all value in

3条回答
  •  情话喂你
    2020-12-06 07:49

    Items that appear to be character when printed but for which R thinks otherwise are generally factor classes objects. I'm also guessing that 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 the quotes:

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

提交回复
热议问题