I have a list of 10 dataframes, on which I want to apply several functions. I am quite new to R. I searched on the internet but can't find the solution.
The dataframes all have the same variables. I want to set the data type of one variable as a factor (which is now integer), having two levels: wetland and no wetland (1 or 0) in every dataframe. This variable is in the third column.
I tried something like this but I can't find the right code:
factorcol = "WETLAND"
datalist[, factorcol] <- lapply(datalist[,factor_cols], factor)
datalist[, factorcol] <- lapply (levels (datalist[,factorcol]))<-c("no wetl","wetl")
Or should I use as.factor
which I would use if I treated a dataframe seperately? And how I apply it to third column of all dataframes in the list?