繁体   English   中英

有没有R function 减少不同数据集的同一套代码?

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

是否有 function 可以减少不同数据集的重复 plot 代码行?

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"))
)

假设您正在使用数据框,首先创建一个列表:

plot_list <- list(prospects6K, testing5K, training15K)

然后你可以使用 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"))
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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