I have the following dataset.
# A tibble: 30,560 x 3
fips year emp
<chr> <chr> <dbl>
1 01001 10 9828
2 01001 20 6261
3 01001 30 8172
4 01001 40 6752
5 01001 50 5957
6 01001 60 5818
7 01001 70 8118
8 01001 80 12433
9 01001 90 15432
10 01001 2000 22847
# … with 30,550 more rows
I would like to get the following output.
# A tibble: 30,560 x 3
fips year emp
<chr> <chr> <dbl>
1 01001 1910 9828
2 01001 1920 6261
3 01001 1930 8172
4 01001 1940 6752
5 01001 1950 5957
6 01001 1960 5818
7 01001 1970 8118
8 01001 1980 12433
9 01001 1990 15432
10 01001 2000 22847
# … with 30,550 more rows
To get this dataset, I wrote the following code. But it would be very tedious. I also try str_pad, but padding "19" could not work. Could you tell me smarter method?
emp %>%
mutate(year= ifelse(year == "00", "1900",
ifelse(year == "10", "1910",
ifelse(year == "20", "1920",
ifelse(year == "30", "1930",
ifelse(year == "40", "1940",
ifelse(year == "50", "1950",
ifelse(year == "60", "1960",
ifelse(year == "70", "1970",
ifelse(year == "80", "1980",
ifelse(year == "90", "1990",
"2000")))))))))))