寻找R中从数据表中提取以下内容的方法。
我想将数字取磅之前的数值。我希望利用“ ####磅”组合之前和之后的数据字段杂乱无章地提取数据。
如果输入是这个:x
我需要将磅输出分别解析:y
如果“ #####磅”在每个记录中仅出现一次,则使用正则表达式将起作用:
x <- c("14 trucks and 3298 pounds of tuna",
"228 gallons and 190 pounds of sand",
"161751 barrels gell, 3438540 pounds proppant",
"29 pounds of hay, 100 barrels of water, 30 pins")
y <- gsub("(^|.* )(\\d+) pounds.*$", "\\2", x)