首页 > 解决方案 > 将“1000,00+”值转换为 R 中的数字会给出警告“强制引入的 NA”?

问题描述

我的数据集有“安装”列,其值如 (“5,000+”、“10,000+”、....)

当我尝试将其转换为数字时,它给了我一个错误的 NA 值:

df <- as.numeric(gsub(",","",df_dataset$Installs))

Warning message:
NAs introduced by coercion 

我想同时替换“+”和“,”符号。我怎样才能做到这一点?

标签: rreplaceall

解决方案


尝试删除所有非数字字符:

Installs_Numeric <- as.numeric(gsub("[,+]+", "", df_dataset$Installs))

推荐阅读