我需要从具有这些属性值的向量中提取开始年份和结束年份。从字符串和文本数据中提取年份
yr<- c("June 2013 – Present (2 years 9 months)", "January 2012 – June 2013 (1 year 6 months)","2006 – Present (10 years)","2002 – 2006 (4 years)")
yr
June 2013 – Present (2 years 9 months)
January 2012 – June 2013 (1 year 6 months)
2006 – Present (10 years)
2002 – 2006 (4 years)
我期待这样的输出。有没有人有建议?
start_yr end_yr
2013 2016
2012 2013
2006 2016
2002 2006
gsub与2016年“现在”并提取四位数字。尝试它 – rawr