0
我有它的整個條目傳播幾個月甚至幾年的字符串列:查找月份和年份內串
df <- data.frame(STRINGS = c("January 2017 Blah Blah",
"February Blah Blah",
"2016 Yeah Yeah",
"March Bleck",
"Stuff"))
> df
STRINGS
1 January 2017 Blah Blah
2 February Blah Blah
3 2016 Yeah Yeah
4 March Bleck
5 Stuff
所有年份的範圍從2015年到2017年
我想輸出如下:
STRINGS MONTH YEAR
1 January 2017 Blah Blah January 2017
2 February Blah Blah February NA
3 2016 Yeah Yeah NA 2016
4 March Bleck March NA
5 Stuff NA NA
這樣做的最簡單方法是什麼?
首先,我有
months <- c("January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December")
years <- c(2015, 2016, 2017)