在df中,我有一个变量‘资格’,并有这样的观察:
我想要创建变量exp (经验年),减去年数,如上面的例子: exp: 6,3,5,2
这是如何做到的呢?
发布于 2021-01-21 19:18:56
使用来自str_extract库的stringr:
library(stringr)
df <- data.frame(qualification = c("a bachelor's degree and 6 years of experience. At least 3 years of experience in the implementation and management...", "at least 3 years of professional experience with strong recommendations from previous supervisors. experience in procurement, office administration, logistics management, and event/meeting coordination.", "non-matching string"))
df$exp <- as.numeric(str_extract(df$qualification, "(\\d+)(?=\\s+year)"))
print(df$exp)
## [1] 6 3 NAhttps://stackoverflow.com/questions/65833859
复制相似问题