Regex 从R中的字符串中高效提取若干数字
假设我有字符串Regex 从R中的字符串中高效提取若干数字,regex,r,string,parsing,Regex,R,String,Parsing,假设我有字符串 x <- " 1.1325 -0.9022 -0.1832 -0.5479 0.1236 -0.6556 -1.0599 -0.8881 -0.2136" 我所取得的成就是: na.omit(as.numeric(strsplit(samp, split = " ")[[1]])) 我的问题:有没有更有效的方法?我们可以使用扫描 scan(text=x, what=numeric(), quiet=TRUE) #[1] 1.1325 -0.9
x <- " 1.1325 -0.9022 -0.1832 -0.5479 0.1236 -0.6556 -1.0599 -0.8881 -0.2136"
我所取得的成就是:
na.omit(as.numeric(strsplit(samp, split = " ")[[1]]))
我的问题:有没有更有效的方法?我们可以使用
扫描
scan(text=x, what=numeric(), quiet=TRUE)
#[1] 1.1325 -0.9022 -0.1832 -0.5479 0.1236 -0.6556 -1.0599 -0.8881 -0.2136
我们可以使用scan
scan(text=x, what=numeric(), quiet=TRUE)
#[1] 1.1325 -0.9022 -0.1832 -0.5479 0.1236 -0.6556 -1.0599 -0.8881 -0.2136