I'm trying to apply a lapply for doing a regression, but I get an error:
A reproducible example
set.seed(42)  
n <- 6
juntar_blocs <- data.frame(id=1:n, 
                           pond_total_index_blocs_iguals = sample(1:n),
                           unitatespecifica = sample(0:1,n, replace = TRUE),
                           responsable = sample(0:1,n, replace = TRUE),
                           actu_transv=  sample(0:1,n, replace = TRUE),
                           util_rec_nuevo_pers = sample(0:1,n, replace = TRUE),
                           ord_aprob = sample(0:1,n, replace = TRUE), 
                           pers_transp_tareas = sample(0:1, n, replace = TRUE), 
                           util_rec_nuevo_pers = sample(0:1, n, replace = TRUE))
My code:
objects for dependent and independent variables
dep<-list("pond_total_index_blocs_iguals") 
variables_index_subst_ <- c("unitatespecifica", "responsable", "actutransv", "util_rec_nuevo_pers", "ord_aprob", "pers_transp_tareas", "util_rec_nuevo_pers")
The database is called juntar_blocs. Then I write the code
models <- lapply(dep, function(x, y)
    step(lm(as.formula(paste(x, paste(y, collapse="+"))), data=juntar_blocs), 
         direction="backward"), y = variables_index_subst_)
I get this error
Error in str2lang(x) : <text>:1:31: unexpected symbol
1: pond_total_index_blocs_iguals unitatespecifica
Thank you!
                              ^
 
    