r - Apply custom function to any dataset with common name -
i have custom function want apply dataset shares common name.
common_funct=function(rank_p=5){ df = any_dataframe_here[any_dataframe_here$rank <rank_p,] return(df) }
i know common functions below value of each.
apply(mtcars,1,mean)
but if wanted :
apply(any_dataset, 1, common_funct(anyvalue))
how pass along?
library(dplyr) mtcars$rank = dense_rank(mtcars$mpg) iris$rank = dense_rank(iris$sepal.length)
now how go applying same function both values?
if understand question, suggest putting data frames list , apply on it. so
## example function common_funct=function(df, rank_p=5){ df[df$rank <rank_p,] } ## sanity check common_funct(mtcars) common_funct(iris)
next create list of data frames
l = list(mtcars, iris)
and use lapply
lapply(l, common_funct)
Comments
Post a Comment