[R] foreign/write.table
Michaell Taylor
pols1oh at bestweb.net
Wed Apr 10 14:12:31 CEST 2002
Hello,
When using write.table I am getting two variables pasted together (not
by choice). Has anyone else had this happen?
Specifically, I have the following on a RH7.2/R1.4 box:
d _ read.dta(paste('/montecarlo/forecast/off/',F,'.dta',sep=''))
write.table(d,file=paste('/montecarlo/forecast/off/csv/',F,'.csv',sep=''),
row.names=FALSE, col.names=FALSE,
quote=FALSE, sep=' , ')
which gives:
[mtaylor at statamatic Verify]$ head
/montecarlo/forecast/off/csv/mcoffmetaa.csv
1,AA2002 ,0.004 , 288000 ,0.004 , 263000 , 0.000 ,-0.015 , -0.014
1,AA2003 ,0.000 , 0 ,0.007 , 493000 , -0.006 ,-0.017 , -0.015
1,AA2004 ,0.000 , 0 ,0.018 , 1273000 , -0.016 ,-0.008 , -0.003
1,AA2005 ,0.000 , 0 ,0.012 , 841000 , -0.010 ,0.033 , 0.037
1,AA2006 ,0.000 , 30000 ,0.018 , 1266000 , -0.015 ,0.054 , 0.059
1,AA2007 ,0.007 , 528000 ,0.026 , 1903000 , -0.018 ,0.047 , 0.052
1,AA2008 ,0.011 , 900000 ,0.036 , 2676000 , -0.022 ,0.041 , 0.046
1,AA2009 ,0.011 , 914000 ,0.025 , 1898000 , -0.012 ,0.070 , 0.073
The problem is with the "AA2002", "AA2003" - as can be seen below - the
R object has metcode and yr as seperate variables.
> d[1:5,]
scenario metcode yr ginv cons gocc abs dvac gmre gmer
1 1 AA 2002 0.004 288000 0.004 263000 0.000 -0.015 -0.014
2 1 AA 2003 0.000 0 0.007 493000 -0.006 -0.017 -0.015
3 1 AA 2004 0.000 0 0.018 1273000 -0.016 -0.008 -0.003
4 1 AA 2005 0.000 0 0.012 841000 -0.010 0.033 0.037
5 1 AA 2006 0.000 30000 0.018 1266000 -0.015 0.054 0.059
I've seen similiar issues when reading dta files, but seems like the R
object is good. i.e.
lapply(d,mode)
$scenario
[1] "numeric"
$metcode
[1] "character"
$yr
[1] "numeric"
<snip>
I've tried ....
d$metcode <- paste(d$metcode,' , ',sep='')
as a cheap work around - no luck.
Any suggestions would be appreciated.
Michaell
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list