Reformatting Year in strange format

You can use stringr() package, for example

library(stringr)

sample_year <- "1960 [YR1960]"

str_extract(sample_year,"^\\d{4}")
#> [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