[R] confusion about write.csv
Mark Leeds
m@rk|eed@2 @end|ng |rom gm@||@com
Fri Jun 5 03:48:34 CEST 2020
Hi Erin: The default for write.csv is col.names = TRUE . So, in the second
one,
if you put, col.names = FALSE, that should work. It's confused right now
because you want to append but also write the column names again.
Mark
On Thu, Jun 4, 2020 at 9:34 PM 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.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list