数据帧,数字被强制为NA

时间:2019-01-04 14:22:29

标签: r dataframe

我有以下数据框:

a <- c(1,2,3,4)
b <- c("Product 1","Product 2","Product 3","Product 4")
c <- c("1,004","1,80","3","18")

db <- data.frame(a,b,c)

db$c <- as.numeric(as.character(db$c))

然后我收到警告消息:

  

强制性引入的不适用

并且用逗号替换具有NA的值。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

db$c <- as.numeric(gsub(",","",db$c))