R语言的一大特色是可以自己编写函数。基本格式是把function赋予一个变量,例子如下:
theData <- function(type="all"){
switch(type,
all=format(Sys.time(),"%Y %m %d %A"),
part=format(Sys.time(),"%y-%m-%d"),
cat("Please retype.")
)
}
theData()
theData("all")
theData("part")
发表评论