[R] Writing out csv files
James Rome
jamesrome at gmail.com
Tue Feb 2 22:00:08 CET 2010
Yes, that worked.
Thank you,
Jim
On 2/2/10 3:45 PM, jim holtman wrote:
> Use 'write.csv'
>
> write.csv(maxr,fname,na="0")
>
> this may work better.
>
>
>> write.table(x.df,sep=',')
>>
> "V1","V2","V3"
> "1",1,4,7
> "2",2,5,8
> "3",3,6,9
>
>> write.csv(x.df)
>>
> "","V1","V2","V3"
> "1",1,4,7
> "2",2,5,8
> "3",3,6,9
>
> write.csv makes it excel compatible.
>
> On Tue, Feb 2, 2010 at 3:32 PM, James Rome <jamesrome at gmail.com> wrote:
>
>> In my code, I calculate the maximum values with 2 factors using
>> maxr=with(arrdf, tapply(rate,list(weekday,quarter), max, na.rm=T))
>>
>> and I want to write out the file so that Excel can read it.
>> I used
>> write.table(maxr, fname, sep=",", col.names=TRUE, row.names=TRUE,
>> quote=TRUE, na="0")
>> which works, and yields something like
>> "0","1","2","3","4","5","6","7","8","9","10","11","12","13","14"
>> "Friday",4,3,2,2,2,2,1,2,2,2,1,2,1,1,1,1,1,2,3,4,5,6,9,8,8,5,8,1
>> "Monday",3,2,1,2,1,2,1,1,1,2,1,0,0,2,2,1,2,2,4,4,4,7,7,7,7,6,8,1
>> "Saturday",4,3,1,1,3,2,1,1,1,2,1,0,0,2,0,1,1,2,5,6,4,5,5,8,8,6,6
>> "Sunday",3,2,4,1,2,2,1,1,2,2,1,0,1,1,1,1,0,1,4,3,5,6,5,8,6,5,5,1
>> "Thursday",3,3,2,3,2,1,0,1,3,1,0,0,1,1,0,0,2,3,4,4,5,5,5,8,6,4,6
>> "Tuesday",5,3,2,2,2,3,1,1,0,0,1,0,1,1,1,1,1,2,3,4,7,5,8,8,7,7,7,
>> "Wednesday",2,3,1,2,2,1,1,1,1,1,1,0,0,0,2,1,1,3,4,6,4,6,11,10,5,
>>
>> The top row is the quarter hours of the day
>>
>> However, when Excel reads this, it will put the first "0" over Friday
>> instead of over the 4.
>>
>> Is there a way to write this out with a "quarter" at the start of the
>> first row? E.g.,
>>
>> "quarter", "0","1","2","3","4","5","6","7","8","9","10","11","12","13","14"
>> "Friday",4,3,2,2,2,2,1,2,2,2,1,2,1,1,1,1,1,2,3,4,5,6,9,8,8,5,8,1
>> "Monday",3,2,1,2,1,2,1,1,1,2,1,0,0,2,2,1,2,2,4,4,4,7,7,7,7,6,8,1
>> "Saturday",4,3,1,1,3,2,1,1,1,2,1,0,0,2,0,1,1,2,5,6,4,5,5,8,8,6,6
>> "Sunday",3,2,4,1,2,2,1,1,2,2,1,0,1,1,1,1,0,1,4,3,5,6,5,8,6,5,5,1
>> "Thursday",3,3,2,3,2,1,0,1,3,1,0,0,1,1,0,0,2,3,4,4,5,5,5,8,6,4,6
>> "Tuesday",5,3,2,2,2,3,1,1,0,0,1,0,1,1,1,1,1,2,3,4,7,5,8,8,7,7,7,
>> "Wednesday",2,3,1,2,2,1,1,1,1,1,1,0,0,0,2,1,1,3,4,6,4,6,11,10,5,
>>
>> And I need to keep the non-standard column names too.
>>
>> Thanks again in advance,
>> Jim Rome
>>
>> ______________________________________________
>> R-help at 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.
>>
>>
>
>
>
More information about the R-help
mailing list