从字符串向量中提取数字我有这样的绳子:years<-c("20 years old", "1 years old")我只想要这个向量的数字。预期产出是一个向量:c(20, 1)我该怎么做呢?
3 回答

繁星淼淼
TA贡献1775条经验 获得超11个赞
gregexpr
:
matches <- regmatches(years, gregexpr("[[:digit:]]+", years))as.numeric(unlist(matches))
regexpr
gregexpr
unlist
.
- 3 回答
- 0 关注
- 609 浏览
添加回答
举报
0/150
提交
取消