Reformatting Year in strange format

Is there any way for me to reformat the year values to get rid of the square brackets? So it only contains 1960 for example.

How is the data formatted? Would just getting the first four characters work? str_sub from stringr perhaps?

You can use stringr() package, for example


sample_year <- "1960 [YR1960]"

#> [1] "1960"

Created on 2019-12-08 by the reprex package (v0.3.0.9000)

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

1 Like

This worked! Thanks so much

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.