R语言中自编函数(例题)


R语言中自编函数(例题)

1、

mystats <- function(x, parametric = TRUE, print = FALSE){ if (parametric) { center = mean(x); spread = sd(x) }else { center <- median(x); spread = mad(x) } if (print & parametric) { cat("Mean = ", center, "\n","\bSD = ", spread, "\n") }else if (print & !parametric) { cat("Median = ", center, "\n", "\bMAD = ", spread,"\n") } result <- list(center = center, spread = spread) return(result) } x <- 1:5 mystats(x) mystats(x,parametric = T,print = T) mystats(x, parametric = F, print = T)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM