Cant convert factor to numeric in R

后端 未结 2 475
夕颜
夕颜 2021-01-16 17:00

I\'ve tried:

  • i <- as.numeric(as.character(Impress))

  • i <- as.numeric(as.character(levels(Impress)))

2条回答
  •  醉话见心
    2021-01-16 17:16

    Because the data has commas, R cannot convert it to a numeric. You have to remove the commas with sub() first and then convert:

    i <- as.numeric(gsub(",", "", as.character(impress)))
    

提交回复
热议问题