我有一个字符变量,列出如下值:
default: cout << "\nInvalid hexadecimal digit " << *i;
我想只提取日期(76GA14, Week 1, 05/13/2014, ABC
76GA14, Week 4, 02/08/2016, ABC
76GA15, Week 3, 09/02/2016, ABC
76GA15, Week 8, 01/19/2015, ABC
76GA16, Week 1, 11/28/2018, ABC
76GA18, Day 0, 12/07/2015, ABC
76GA18, Day 2 End, 11/22/2016, ABC
76GA17, W4 end 6DNV118, 07/06/2016, ABC
...
)并设置创建一个包含这些值的新变量列。
答案 0 :(得分:1)
有很多方法可以做到这一点。
这是我的建议:
charVector <- c("76GA14, Week 1, 05/13/2014, ABC",
"76GA14, Week 4, 02/08/2016, ABC",
"76GA15, Week 3, 09/02/2016, ABC",
"76GA15, Week 8, 01/19/2015, ABC",
"76GA16, Week 1, 11/28/2018, ABC")
newVariable <- sapply(strsplit(charVector, ", "), "[", 3)