码迷,mamicode.com
首页 > 编程语言 > 详细

R语言读取文件数据

时间:2015-10-14 17:49:32      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

R语言读取文件数据

  
??1.read.table()函数

 技术分享

2.其他函数的缺省

read.csv(file, header = TRUE, sep = ",", quote="\"", dec=".",
fill = TRUE, ...)
read.csv2(file, header = TRUE, sep = ";", quote="\"", dec=",",
fill = TRUE, ...)
read.delim(file, header = TRUE, sep = "\t", quote="\"", dec=".",
fill = TRUE, ...)
read.delim2(file, header = TRUE, sep = "\t", quote="\"", dec=",",
fill = TRUE, ...)

3.scan函数可以改变参数类型

> mydata <- scan("data.dat", what = list("", 0, 0))

scan(file = "", what = double(0), nmax = -1, n = -1, sep = "",
quote = if (sep=="\n") "" else "’\"", dec = ".",
skip = 0, nlines = 0, na.strings = "NA",
flush = FALSE, fill = FALSE, strip.white = FALSE, quiet = FALSE,
blank.lines.skip = TRUE, multi.line = TRUE, comment.char = "")

技术分享

4.read.fwf()可以读取文件中具有一定宽度的数据

read.fwf(file, widths, sep="\t", as.is = FALSE,
skip = 0, row.names, col.names, n = -1, ...)

widths可以设定宽度

> mydata <- read.fwf("data.txt", widths=c(1, 4, 3))
> mydata
V1 V2 V3
1 A 1.50 1.2
2 A 1.55 1.3
3 B 1.60 1.4
4 B 1.65 1.5
5 C 1.70 1.6
6 C 1.75 1.7

5.写入数据write.table()

write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
eol = "\n", na = "NA", dec = ".", row.names = TRUE,
col.names = TRUE, qmethod = c("escape", "double"))

技术分享

 


?? ?? ?????? 
?? ??


?? ?? ?????? 
?? ??

??

R语言读取文件数据

标签:

原文地址:http://www.cnblogs.com/chance88/p/4877792.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!