Jinsong Zhao
2015-Aug-16 14:38 UTC
[R] difference between write.csv(...) and write.table(..., sep=", ")
Hi there, I notice that write.csv is a wrap of write.table. However, I can't get the same results using both functions. Here is a reproducible example: > x <- matrix(1:6, nrow =2) > rownames(x) <- letters[1:2] > colnames(x) <- LETTERS[1:3] > write.csv(x, "") "","A","B","C" "a",1,3,5 "b",2,4,6 > write.table(x, "", sep = ",") "A","B","C" "a",1,3,5 "b",2,4,6 The difference of outputs from both functions is clear. Is it possible to get the same results of write.csv using write.table? Any suggestions will be really appreciated. Thanks in advance. Best, Jinsong
Michael Dewey
2015-Aug-16 14:53 UTC
[R] difference between write.csv(...) and write.table(..., sep=", ")
I think that if you do ?write.csv and then page down to the section entitled CSV files the mystery will be solved for you in the first few paragraphs. On 16/08/2015 15:38, Jinsong Zhao wrote:> Hi there, > > I notice that write.csv is a wrap of write.table. However, I can't get > the same results using both functions. Here is a reproducible example: > > > x <- matrix(1:6, nrow =2) > > rownames(x) <- letters[1:2] > > colnames(x) <- LETTERS[1:3] > > write.csv(x, "") > "","A","B","C" > "a",1,3,5 > "b",2,4,6 > > write.table(x, "", sep = ",") > "A","B","C" > "a",1,3,5 > "b",2,4,6 > > The difference of outputs from both functions is clear. > > Is it possible to get the same results of write.csv using write.table? > > Any suggestions will be really appreciated. Thanks in advance. > > Best, > Jinsong > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Michael http://www.dewey.myzen.co.uk/home.html
Berend Hasselman
2015-Aug-16 14:57 UTC
[R] difference between write.csv(...) and write.table(..., sep=", ")
> On 16-08-2015, at 16:38, Jinsong Zhao <jszhao at yeah.net> wrote: > > Hi there, > > I notice that write.csv is a wrap of write.table. However, I can't get the same results using both functions. Here is a reproducible example: > > > x <- matrix(1:6, nrow =2) > > rownames(x) <- letters[1:2] > > colnames(x) <- LETTERS[1:3] > > write.csv(x, "") > "","A","B","C" > "a",1,3,5 > "b",2,4,6 > > write.table(x, "", sep = ",") > "A","B","C" > "a",1,3,5 > "b",2,4,6 > > The difference of outputs from both functions is clear. > > Is it possible to get the same results of write.csv using write.table? >Yes. Read the item col.names in the help for write.table and go to the section ?CSV files?.. Use write.table(x, "", sep = ",", col.names=NA) Learn to use R?s help. Berend> Any suggestions will be really appreciated. Thanks in advance. > > Best, > Jinsong > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Marc Schwartz
2015-Aug-16 14:59 UTC
[R] difference between write.csv(...) and write.table(..., sep=", ")
> On Aug 16, 2015, at 9:38 AM, Jinsong Zhao <jszhao at yeah.net> wrote: > > Hi there, > > I notice that write.csv is a wrap of write.table. However, I can't get the same results using both functions. Here is a reproducible example: > > > x <- matrix(1:6, nrow =2) > > rownames(x) <- letters[1:2] > > colnames(x) <- LETTERS[1:3] > > write.csv(x, "") > "","A","B","C" > "a",1,3,5 > "b",2,4,6 > > write.table(x, "", sep = ",") > "A","B","C" > "a",1,3,5 > "b",2,4,6 > > The difference of outputs from both functions is clear. > > Is it possible to get the same results of write.csv using write.table? > > Any suggestions will be really appreciated. Thanks in advance. > > Best, > Jinsong> write.csv(x)"","A","B","C" "a",1,3,5 "b?,2,4,6> write.table(x, sep = ",", qmethod = "double", col.names = NA)"","A","B","C" "a",1,3,5 "b?,2,4,6 Read the section on CSV files in ?write.table Regards, Marc Schwartz