首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >根据模式提取R中的元素

根据模式提取R中的元素
EN

Stack Overflow用户
提问于 2021-01-21 18:43:49
回答 1查看 19关注 0票数 0

在df中,我有一个变量‘资格’,并有这样的观察:

  • ,学士学位,6年工作经验。至少3年的执行经验和management...
  • at至少3年的专业经验,并有来自前任主管的强烈建议。有相关领域采购、办公室管理、物流管理和活动/会议coordination.
  • a ba/s或同等学历的经验;至少5年ngo...
  • bachelor's学位。·2年相关工作经验.

我想要创建变量exp (经验年),减去年数,如上面的例子: exp: 6,3,5,2

这是如何做到的呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-21 19:18:56

使用来自str_extract库的stringr

代码语言:javascript
复制
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 NA
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65833859

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档