简体   繁体   中英

Is there an R function to reduce the same sets of code for different data sets?

Is there a function where I can reduce the line of repeated plot codes for different data sets?

plot_missing(prospects6K, 
             group = c("Excellent" = 0.01, "Good" = 0.3, "Ok" = 0.6, "Bad" = 0.9),
             missing_only = T,
             title= "Missing User Data",
             ggtheme = theme_minimal(),
             theme_config = list(legend.position = c("bottom"))
)

plot_missing(testing5K, 
             group = c("Excellent" = 0.01, "Good" = 0.3, "Ok" = 0.6, "Bad" = 0.9),
             missing_only = T,
             title= "Missing User Data",
             ggtheme = theme_minimal(),
             theme_config = list(legend.position = c("bottom"))
)

plot_missing(training15K, 
             group = c("Excellent" = 0.01, "Good" = 0.3, "Ok" = 0.6, "Bad" = 0.9),
             missing_only = T,
             title= "Missing User Data",
             ggtheme = theme_minimal(),
             theme_config = list(legend.position = c("bottom"))
)

Assuming you are working with data frames, first create a list of them:

plot_list <- list(prospects6K, testing5K, training15K)

Then you can use lapply:

lapply(plot_list, \(x) plot_missing(x, 
             group = c("Excellent" = 0.01, "Good" = 0.3, "Ok" = 0.6, "Bad" = 0.9),
             missing_only = T,
             title= "Missing User Data",
             ggtheme = theme_minimal(),
             theme_config = list(legend.position = c("bottom"))
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM