Just started using R, so forgive me if my code/question are a bit obtuse.
I've created a list of variables names. I'd like to check if the variables in this list are present in another dataframe (lfs_ja20). Should I use a for loop, or the lapply function? Have I even created the list appropriately?
#create list of relevant variables
varlist <- tibble::lst("ACTHR","ADDJOB","AGE","AGES","AGWRK","AXFA","AXPA","BACTHR",
"BANDG","BEFOR","BUSHR","CONMON","COUNTRY","CURED8","DIFJOB",
"DISEA","DURUN")
#my failed attempt at a loop, which results in no error message, but yields nothing
for(i in varlist) {
find_var(lfs_ja20,i)
}
#my failed attempt at creating a search function then using lapply, which yields the following error
message : Error in FUN(X[[i]], ...) : argument "y" is missing, with no default
searchvar <- function(x,y) names(y[grep(x, names(y))])
lapply(varlist, searchvar)
Thank you. If there's any part of this question that is unclear, some quick advice on its framing would be helpful also.