I'm try to do a feature selection on a dataframe list using the caret package. I have different dataframes but the last 6 columns are the same. When I am trying to apply the model on a single df it works fine
# For a single dataframe
mx.chem # the name of my single dataframe
#define the control
mx.control <- rfeControl(functions=rfFuncs, method = "cv", number = 10)
# run the rfe
mx.results <- rfe(mx.chem[,1:22], mx.chem[,23], sizes = c(1:22), rfeControl = mx.control)
print(mex.results)
but My problem is when I try to use lapply on a list of df. The code I have until now is
require(mlbench)
require(caret)
mylist # is a df list containing 3 df
for (i in 1:3) {
my.control <- rfeControl(functions=rfFuncs, method = "cv", number = 10) # define the control
longdata <- length(i)-6
idxindustry <- longdata +1
my.results <- lapply(mylist, function(x) rfe ( x[,1:longdata], x[,idxindustry], data = x, sizes =c(1:longdata), rfeControl = my.control))
}
I'm not sure if I'm using column index properly. Does anyone have an idea how to fix to make my code work. Thanks
dataargument for rfe. Link here. It is currently being passed to the model fitting. Is that intended? - Pierre Llongdata <- length(i)-6is not doing what you think.itakes on three values1 2 3. So you wantlongdatato belength(1)-6and so on? The length of a single number is always1. Solongdatais-5each time. Do you see why? - Pierre Lforloop that is looping through1 2 3- Pierre Llapply, not both - Pierre L