ERROR: model.frame.default : invalid type(NULL)

Hi, this is hard to tell without the test object. The way to fix this is with a reprex. See the FAQ. That way, everyone interested in helping can see what you are seeing. Here's what one looks like using a simulated dataset and taking a functional programming approach.

# f(x) = y
# step 1: create fake_data
# x: col 1:7 are loanfile data
# y: col 8:12 are control flags to be set
var_num <- 12
fake_rows <- 90
set.seed(42)
input <- sample(c(TRUE,FALSE),var_num * fake_rows, 
                replace = TRUE)
m <- matrix(input, nrow = fake_rows, ncol = var_num)
col_header <- c("BLACK","HISPANIC","API","FEMALE",
                "lowmod","elder","majblhs","c_minority",
                "c_gender", "c_lowmod", "c_elder","c_majblhs")
colnames(m) <- col_header
# control flags intitially set FALSE
m[,8:12] <- FALSE
before = head(m)

# step 2: f to set control flags

m[which(rowSums(m[,1:3]) > 0),8] <- TRUE
m[which(m[,4]),9] <- TRUE
m[which(m[,5]),10] <- TRUE
m[which(m[,6]),11] <- TRUE
m[which(m[,7]),12] <- TRUE
after <- head(m)

# show example of which control flags were changed
# from FALSE to TRUE
(before == after)[,8:12]
#>      c_minority c_gender c_lowmod c_elder c_majblhs
#> [1,]      FALSE    FALSE    FALSE    TRUE     FALSE
#> [2,]      FALSE    FALSE    FALSE   FALSE     FALSE
#> [3,]      FALSE     TRUE    FALSE    TRUE      TRUE
#> [4,]      FALSE    FALSE     TRUE    TRUE      TRUE
#> [5,]       TRUE     TRUE    FALSE   FALSE     FALSE
#> [6,]       TRUE    FALSE     TRUE   FALSE     FALSE