使用stringr包的str_replace_all的时候,出现报错:Warning message:In stri_replace_all_regex(string, pattern, fix_replacement(replacement), :argument is not an atomic vector; coercing。原因是,字段内既有数字,也有文本。
#去除单位kg
data$商品毛重<-str_replace_all(data$商品毛重,"kg","")
Warning message:
In stri_replace_all_regex(string, pattern, fix_replacement(replacement), :
argument is not an atomic vector; coercing
解决方案:把字段转换成文本,再替换字符。具体如下:
data$商品毛重<-str_replace_all(as.character(data$商品毛重),"kg","")