摘要: 1、自定义函数 test1 <- function(x = 5,y) ## 自定义函数test { a = x / y print(a) } test1(10,100) ## 使用位置参数,按顺序x = 10, y = 100 test1(y = 10, x = 100) ## 关键字参数 直接定义 阅读全文
posted @ 2021-06-29 22:09 小鲨鱼2018 阅读(1505) 评论(0) 推荐(0) 编辑
摘要: 1、 rm(list = ls()) dir() for (i in list.files(pattern=".r$")) { source(i) } 2、 rm(list = ls()) dir() for (i in dir()) { if(substr(i,nchar(i)-1,nchar(i 阅读全文
posted @ 2021-06-29 00:16 小鲨鱼2018 阅读(137) 评论(0) 推荐(0) 编辑
摘要: R语言中如何在函数内部定义全局变量。 1、在函数内部定义的变量无法在函数外调用 test1 <- function(x, y) { a <- x + y print(a) } test1(10,20) print(a) 2、在函数内定义全局变量 test2 <- function(x, y) { a 阅读全文
posted @ 2021-06-29 00:00 小鲨鱼2018 阅读(1367) 评论(0) 推荐(0) 编辑