我有一个表,我试图操纵它以提取年份值并将其放入该表的新字段中。例如:
原始表
@Override
protected Map<String,String> getParams(){
Map<String, String> params = new HashMap<String, String>();
params.put("MY_FIRST_DATA_KEY", "MY_FIRST_DATA_VALUE");
params.put("MY_SECOND_DATA_KEY", "MY_SECOND_DATA_VALUE");
return params;
}
所需结果
Code Description
A Acme (1985 - 2002)
B Coakc (2011 - 2012)
A Jupiter(11) (2011 - )
C Capital Management Corporation (2011 - )
D Diuretics Inc (2011 - )
E Charter (2011 - )
我在想类似的东西:
答案 0 :(得分:3)
使用tidyverse
框架,您可以按以下方式进行操作
library(dplyr)
library(stringr)
df %>% mutate(Start_year=str_match(Description,"(?<=\\()\\d{4}"),
End_year=str_match(Description,"\\d{4}(?=\\))"))