e <<- data.env ## here i am storing my rdata
data_frames <- Filter(function(x) is.data.frame(get(x)), ls(envir = e)) ## getting only dataframe
for(i in data_frames) e[[i]] <<- mytest_function(e[[i]]) ### here i am iterating the dataframe
Now, how do I convert the for loop into an apply function? The loop takes so long to iterate.
>Solution :
It’s unclear what you want the result to be. However, if you are just wanting to apply a function to each column in a dataframe, then you can just use sapply.
sapply(df, function(x) mytest_function(x))
Or if you already have a list of a dataframes and are applying a function to each dataframe, then I would use purrr.
library(purrr)
purrr::map(data_frames, mytest_function)