我需要從具有這些屬性值的向量中提取開始年份和結束年份。從字符串和文本數據中提取年份
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