[R] confusion about write.csv

Erin Hodgess er|nm@hodge@@ @end|ng |rom gm@||@com
Fri Jun 5 04:12:11 CEST 2020


Thanks to all for the help.

I found that write.table works nicely, with col.names = FALSE with append =
TRUE.

Sincerely,
Erin

Erin Hodgess, PhD
mailto: erinm.hodgess using gmail.com


On Thu, Jun 4, 2020 at 7:56 PM Jeff Newmiller <jdnewmil using dcn.davis.ca.us>
wrote:

> Use write.table.
>
> Write.csv follows a very specific definition for csv... one element of
> which is that it is not allowed to have a second header line after data
> lines. The only way for write.csv to enforce this is to disallow appending.
>
> On June 4, 2020 6:34:14 PM PDT, Erin Hodgess <erinm.hodgess using gmail.com>
> wrote:
> > Hello!
> >
> >Hope everyone is doing as well as possible.
> >
> >I have a question about write.csv.  I thought that the append argument
> >would permit adding another data frame with the same column names.
> >
> >Here is my example:
> >
> > date1 <- as.Date("2020-03-09")
> > wday <- weekdays(date1)
> > x1 <- data.frame(date=date1,day=wday,lev=1:5,y=rnorm(5))
> > x1
> >        date    day lev           y
> >1 2020-03-09 Monday   1 -0.09543049
> >2 2020-03-09 Monday   2  0.53943428
> >3 2020-03-09 Monday   3 -0.79224851
> >4 2020-03-09 Monday   4  0.68168147
> >5 2020-03-09 Monday   5 -1.02902897
> > write.csv(file="test1.csv",x1,row.names=FALSE)
> > date1 <- date1 + 1
> > wday <- weekdays(date1)
> > x2 <- data.frame(date=date1,day=wday,lev=1:5,y=rnorm(5))
> > x2
> >        date     day lev          y
> >1 2020-03-10 Tuesday   1 -0.6648301
> >2 2020-03-10 Tuesday   2 -0.1137580
> >3 2020-03-10 Tuesday   3  1.6532675
> >4 2020-03-10 Tuesday   4 -0.5845293
> >5 2020-03-10 Tuesday   5  0.2849392
> > write.csv(file="test1.csv",x2,row.names=FALSE,append=TRUE)
> >Warning message:
> >In write.csv(file = "test1.csv", x2, row.names = FALSE, append = TRUE)
> >:
> >  attempt to set 'append' ignored
> >
> >The values from x2 appear in the test1.csv file.
> >
> >What am I missing, please?
> >
> >Thanks,
> >Erin
> >
> >
> >Erin Hodgess, PhD
> >mailto: erinm.hodgess using gmail.com
> >
> >       [[alternative HTML version deleted]]
> >
> >______________________________________________
> >R-help using 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.
>
> --
> Sent from my phone. Please excuse my brevity.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list