一、读入文件
x<- read.table("input.txt")
head (x)
x<- read.table("input.csv")
x<- read.table("input.csv",sep=",")
x <- read.table("input.csv",sep=",",header =T)
x<-read.table("input.test.txt",sep=",",header =T,skip=5)
x<- read.table ("input.csv",sep=",",header =T,nrows = 100)
##读取,51-151行
x<- read.table
("input.csv",sep=",",header-T,skip-50,nrows= 100)
##默认分隔符为,
x<- read.csv("input.csv")
二、写文件到本地
?write
?write.table
?write.csv
getwd()
write.table (x,file=newfile.txt)
write.table (x,file=newfile.csv,sep="\t")
##去除行号
write.table (x,file=newfile.csv,sep=",",row.names=FALSE)
##追加写入
write.table (x,file=newfile.csv,sep=",",row.names=FALSE,append=T)
write.table(x,file=newfile.csv,sep="\t",quote=FALSE,append=FALSE, na="NA")
##写入压缩文件
write.table(x,file=gzfile (newfile.csv.gz),sep="\t"
quote-FALSE,append=FALSE,na-"NA")
##其他格式,使用foreign包
library(foreign)
write.arff()
三、读入excel文件
本地需要安装JAVA
library(XLConnect)
ex<-loadWorkbook("data.xlsx")
data<-readWorkSheet(ex,1)
四、存储为RDS文件
saveRDS(iris,file="iris.RDS")
readRDS("iris.RDS")
五、存储为Rdata
类似保存项目
save(iris,iris3,file*"XXX/Desktop/iris.Rdata")
load("XXX/Desktop/iris.Rdata") save.image()
版权声明:本文为weixin_39348931原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。