6、R语言,调用自编函数

来源:互联网 发布:建筑工程造价软件 编辑:程序博客网 时间:2024/05/18 07:29
#选择日期的格式
mydate <- function(type = "long"){
  switch(type,
         long = format(Sys.time(), "%A %B %d %Y"),
         short = format(Sys.time(), "%m-%d-%y"),
         cat(type, "is not a recognized type\n")
         )
  

}

上面为自编函数,保存为mydate.R文件

调用:

> source("mydate.R")

> mydate("long")
[1] "星期二 三月 24 2015"
> mydate("short")
[1] "03-24-15"
> mydate("")
 is not a recognized type

0 0
原创粉丝点击