Проблема
У меня есть информация о финансовых годах, встроенная в строки в форме 2019-20 в переменной table_name
(см. Пример ниже).Мне нужно удалить век ( 20 19) и соединить его с компонентом года (20 20 ).В этом примере успех будет выглядеть как 2020 .
Данные
df <- structure(list(table_name = c("Resident tax rates for 2016-17",
"Resident tax rates for 2016-17", "Resident tax rates for 2016-17",
"Resident tax rates for 2016-17", "Resident tax rates for 2015-16",
"Resident tax rates for 2015-16"), taxable_income = c("$18,201 – $37,000",
"$37,001 – $87,000", "$87,001 – $180,000", "$180,001 and over",
"$18,201 – $37,000", "$37,001 – $80,000"), tax_on_this_income = c("19c for each $1 over $18200",
"$3572 plus 32.5c for each $1 over $37000", "$19822 plus 37c for each $1 over $87000",
"$54232 plus 45c for each $1 over $180000", "19c for each $1 over $18200",
"$3572 plus 32.5c for each $1 over $37000"), cumm_tax_amt = c(0,
3572, 19822, 54232, 0, 3572), tax_rate = c(19, 32.5, 37, 45,
19, 32.5), threshold = c(18200, 37000, 87000, 180000, 18200,
37000)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-6L))
Моя попытка
str_extract(df$table_name, pattern = "\\b\\d+\\b\\-(?=\\d+\\b)")