write.csv()函数--R语⾔函数功能:
write.table prints its required argument x
(after converting it to a data frame if it is not one nor a matrix)
to a file or connection.
将X输出到⽂件或者链接
函数语法:
write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
eol = "\n", na = "NA", dec = ".", row.names = TRUE,
col.names = TRUE, qmethod = c("escape", "double"),
fileEncoding = "")
false是什么函数write.csv(...)
write.csv2(...)
函数参数
x
the object to be written, preferably a matrix or data frame.
If not, it is attempted to coerce x to a data frame.
要写⼊的对象,最好是矩阵或数据框。 如果不是,则尝试将x强制转换为数据框。
file
either a character string naming a file or a connection open for writing.
"" indicates output to the console.
表⽰⽂件名的字符串或者链接。“”表⽰输出到控制台
> studentID <- c(1,2,3,4,5)
> gender <- c('M','F','M','M','F')
> math <- c(40,60,70,60,90)
> English <- c(98,56,78,93,79)
> Chinese <- c(86,54,78,90,98)
> data <- data.frame(studentID,gender,math,English,Chinese,stringsAsFactors = F)
> data
studentID gender math English Chinese
11      M  409886
22      F  605654
33      M  707878
44      M  609390
55      F  907998
> write.csv(data,"") "","studentID","gender","math","English","Chinese"
"1",1,"M",40,98,86
"2",2,"F",60,56,54
"3",3,"M",70,78,78
"4",4,"M",60,93,90
"5",5,"F",90,79,98
“” :输出到控制台
append
logical. Only relevant if file is a character string.
If TRUE, the output is appended to the file.
If FALSE, any existing file of the name is destroyed.
逻辑值,当⽂件名为字符串时(⾮链接)使⽤有效,若取值为TRUE,输出结果会新增到原⽂件中,若取值为FALSE,新输出结果替换原⽂件。默认取值为FALSE,替换原⽂件
append=FALSE,默认取值,此时新输出数据将替代原数据
append=TRUE,则在原数据上新增,write.csv⽆法使⽤
These wrappers are deliberately inflexible:
they are designed to ensure that the correct conventions are used to write a valid file.
Attempts to change append, col.names, sep, dec or qmethod are ignored, with a warning.
这些包装程序是故意不灵活的:
它们旨在确保使⽤正确的约定来写⼊有效⽂件。 尝试更改append, col.names, sep, dec or qmethod尝试将被忽略,并显⽰警告。write.table函数才可以使⽤
quote
a logical value (TRUE or FALSE) or a numeric vector.
If TRUE, any character or factor columns will be surrounded by double quotes.
If a numeric vector, its elements are taken as the indices of columns to quote.
In both cases, row and column names are quoted if they are written.
If FALSE, nothing is quoted.
引⽤
逻辑值(TRUE或FALSE)或数字向量。 如果为TRUE,则任何字符或因⼦列都将⽤双引号引起来。 如果是数字⽮量,则将其元素⽤作要引⽤的列的索引。 在这两种情况下,如果都写了⾏名和列名,则要加引号。 如果为FALSE,则不引⽤任何内容。
sep
the field separator string. Values within each row of x are separated by this string.
分隔符
eol
the character(s) to print at the end of each line (row).
For example, eol = "\r\n" will produce Windows' line endings on a Unix-alike OS,
and eol = "\r" will produce files as expected by Excel:mac 2004.
na
the string to use for missing values in the data.
⽤于缺失值的字符
dec
the string to use for decimal points in numeric or complex columns:
must be a single character.
数值或者复数型数值列中⽤于⼩数点的字符,取值必须为单个字符。
write.table(data,'C:\\Users\\***\\Desktop\\c1.txt',
dec=',')
row.names
either a logical value indicating whether the row names of x
are to be written along with x,
or a character vector of row names to be written.
⾏名
逻辑值,指⽰x的⾏名是否要与x⼀起写⼊,或者为要写⼊的⾏名的字符向量。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。