readr::read_csv("~/Desktop/grist.csv") -> a
#>
#> ── Column specification ────────────────────────────────────────────────────────
#> cols(
#> date = col_character(),
#> OCC2010 = col_character(),
#> SKILLOCC = col_double()
#> )
dat <- data.frame(date = c(
"1992-1", "1992-1", "1992-1", "1992-2",
"1992-2", "1992-2"
), OCC2010 = c(
"8460", "7390", "9999", "244",
"2349", "0592"
), SKILLOCC = c(4, 0, 4, 0, 0, 0))
dat
#> date OCC2010 SKILLOCC
#> 1 1992-1 8460 4
#> 2 1992-1 7390 0
#> 3 1992-1 9999 4
#> 4 1992-2 244 0
#> 5 1992-2 2349 0
#> 6 1992-2 0592 0
span <- 8460:9999
check_entry <- function(x, y, z) which(x[,y] %in% z)
dat[,3][check_entry(dat,2,span)] <- 3
dat
#> date OCC2010 SKILLOCC
#> 1 1992-1 8460 3
#> 2 1992-1 7390 0
#> 3 1992-1 9999 3
#> 4 1992-2 244 0
#> 5 1992-2 2349 0
#> 6 1992-2 0592 0
This works even though dat[,2] is typeof chr.