[R] Writing data frames

Gabor Grothendieck ggrothendieck at myway.com
Tue Dec 30 03:04:04 CET 2003



Try this with the m in your example:

write.table(t(m), file="c:/R/tst.txt", col.names=names(m), row.names=F, quote=F, append=F)


---
Date: Mon, 29 Dec 2003 16:21:15 -0800 
From: Ton van Daelen <tvandaelen at scitegic.com>
To: <r-help at stat.math.ethz.ch> 
Subject: [R] Writing data frames 

 
 
Hi there -



I have been trying to generate some simple stats and save the results to
a file. My data looks like this:



x y z exp

0 3 5 1

2 11 10 1

4 4 5 1

7 6 4 1

11 1 2 2

5 7 1 2

3 3 3 2

1 6 1 2



and the script I ran is:



===========

data <- read.table("c:\\R\\data.txt", header=T)

attach(data)

m <- tapply(x, exp, mean)

write.table(m, file="c:\\R\\tst.txt", col.names=T, row.names=F, quote=F,
append = FALSE)

============



I'd like to write the full contents of m:



1 2 

3.25 5.00



to a file, but the write.table call gives me an error: 



Error in as.data.frame.default(x[[i]], optional = TRUE) : 

can't coerce array into a data.frame



Can anyone tell me what the most convenient/flexible way is to write
data.frames?



Thanks - Ton



Ton van Daelen, PhD
Director, Application Support
Tel: (858) 279-8800 ext 217
Fax: (858) 279-8804

Web: www.scitegic.com
SciTegic Inc. - ask more of your data




More information about the R-help mailing list