RE: [R] Writing data frames

About this list Date view Thread view Subject view Author view Attachment view

From: Simon Fear (Simon.Fear@synequanon.com)
Date: Tue 30 Dec 2003 - 21:25:35 EST


Message-id: <6C8A8033ABC1E3468048ABC4F13CE572F0215E@synequanon01>

Another way in this particular case is to transpose m:

write.table(t(m), file="", row.names=FALSE,quote=FALSE)

This transposition creates a 1x2 matrix, for which there is
a method (as.data.frame.matrix). (Don't just use as.matrix(m),
that will be a 2x1 matrix.)

Note that there is a missing dimension spec in the structure of
the array object m - contrast str(m) with str(t(m)). Arrays exist to
be ragged - so there's no default coercion method to the
non-ragged data.frame class.

You could also skip all of the above and work with sink() instead
of write.table().

> -----Original Message-----
> From: Andy Bunn [mailto:abunn@montana.edu]
> Sent: 30 December 2003 00:44
> To: 'Ton van Daelen'; r-help@stat.math.ethz.ch
> Subject: RE: [R] Writing data frames
>
>
> Security Warning:
> If you are not sure an attachment is safe to open please contact
> Andy on x234. There are 0 attachments with this message.
> ________________________________________________________________
>
> The key is in the error message:
> "...can't coerce array into a data.frame"
>
> Even if as.data.frame.default is unhappy you can coerce m into a
> data.frame.
>
> write.table(data.frame(m1 = m[1], m2 = m[2]), file="C:\\R\\tst.txt",
> col.names=T, row.names=F, quote=F, append = FALSE)
>
> There's probably a nicer way to do the coercion but this works.
>
> HTH, Andy
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
 
Simon Fear
Senior Statistician
Syne qua non Ltd
Tel: +44 (0) 1379 644449
Fax: +44 (0) 1379 644445
email: Simon.Fear@synequanon.com
web: http://www.synequanon.com
  
Number of attachments included with this message: 0
  
This message (and any associated files) is confidential and\...{{dropped}}

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Thu 01 Jan 2004 - 09:21:04 EST