Thanks Louis! That seems to work!

On Fri, Feb 8, 2013 at 10:06 AM, Louis Aslett <lasl...@louisaslett.com>wrote:

> I believe your problem stems from using ifelse() actually ... it
> requires the statements which it runs to return a value with the same
> shape as the test, which write.table() isn't doing.
>
> Just change it to a regular if with an else and you'll be fine:
>
> for(i in 1:2){
>   mat <- data.frame(sample(1:30,9),3,3)
>   colnames(mat) <- letters[1:3]
>   if(i == 1){
>     write.table(mat,paste('test.txt',sep=''),row.names=F)
>   } else {
>
> write.table(mat,paste('test.txt',sep=''),row.names=F,col.names=F,append=TRUE)
>   }
> }
>
> Hope that helps,
>
> Louis
>
>
> On Fri, Feb 8, 2013 at 2:40 PM, Brian Smith <bsmith030...@gmail.com>
> wrote:
> >
> > Hi,
> >
> > I am trying to append tables on file with this sample code:
> >
> >         for(i in 1:2){
> >             mat <- data.frame(sample(1:30,9),3,3)
> >             colnames(mat) <- letters[1:3]
> >             ifelse(i ==
> > 1,write.table(mat,paste('test.txt',sep=''),row.names=F),
> >
> >
> write.table(mat,paste('test.txt',sep=''),row.names=F,col.names=F,append=TRUE))
> >         }
> >
> > However, this gives an error:
> >
> > "Error in ifelse(i == 1, write.table(mat, paste("test.txt", sep = ""),  :
> >   replacement has length zero"
> >
> > - Should I be passing in some other parameters or using a different
> > function to append tables to file?
> >
> > thanks!
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@r-project.org mailing list
> > 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]]

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to