我试图从一个句子中提取数字,然后将这些数字放在一起作为一个数字数组。例如,
string<-" The Team: $74,810 TOTAL RAISED SO FARJOIN THE TEAM Vik Muniz
Amount Raised: $70,560 71% Raised of $100,000 Goal CDI International,
Inc. Amount Raised: $2,070 Robert Goodwin Amount Raised: $1,500
30% Raised of $5,000 Goal Marcel Fukayama Amount Raised:
$210 Maitê Proença Amount Raised: $140
Thiago Nascimento Amount Raised: $120
Lydia Kroeger Amount Raised: $80 "
为了继续,我首先删除了逗号,以便可以轻松提取数字:
string.nocomma <- gsub(',', '', string)
然后我试图把这些数字放在一起作为一个数字向量:
fund.numbers <-unique(as.numeric(gsub("[^0-9]"," ",string.nocomma),""))
以下是问题:
R 在最后一个命令之后抛出错误。错误如下:
Warning message: In unique(as.numeric(gsub("[^0-9]", " ", website.fund.nocomma), : NAs introduced by coercion
即使我修复了上述错误并拥有数值向量,我也不确定如何将数值向量转换为数值数组。
有人能帮我吗?谢谢,