R语言的清屏命令

Python014

R语言的清屏命令,第1张

命令代码参考如下:

# An R function to clear the screen on RGui:

cls <- function() {

if (.Platform$GUI[1] != "Rgui")

return(invisible(FALSE))

if (!require(rcom, quietly = TRUE)) # Not shown any way!

stop("Package rcom is required for 'cls()'")

wsh <- comCreateObject("Wscript.Shell")

if (is.null(wsh)) {

return(invisible(FALSE))

} else {

comInvoke(wsh, "SendKeys", "\014")

return(invisible(TRUE))

}

}

#cls() # test

# If you want to make sure that it worked (well, not 100% sure, but...)

res <- cls()

if (res) cat("Console should be cleared now!\n")

使用data.frame函数就可以初始化一个Data Frame。比如我们要初始化一个student的Data Frame其中包含ID和Name还有Gender以及Birthdate,那么代码为:

student<-data.frame(ID=c(11,12,13),Name=c("Devin","Edward","Wenli"),Gender=c("M","M","F"),Birthdate=c("1984-12-29","1983-5-6","1986-8-8”))

另外也可以使用read.table() read.csv()读取一个文本文件,返回的也是一个Data Frame对象。读取数据库也是返回Data Frame对象。