從字符串向量中提取數(shù)字我有這樣的繩子:years<-c("20 years old", "1 years old")我只想要這個向量的數(shù)字。預(yù)期產(chǎn)出是一個向量:c(20, 1)我該怎么做呢?
3 回答

茅侃侃
TA貢獻1842條經(jīng)驗 獲得超21個贊
gregexpr
:
matches <- regmatches(years, gregexpr("[[:digit:]]+", years))as.numeric(unlist(matches))
regexpr
gregexpr
unlist
.
- 3 回答
- 0 關(guān)注
- 653 瀏覽
添加回答
舉報
0/150
提交
取消