[R] write.table

Huang, Guo-Hao guohao.huang at gmail.com
Fri Feb 20 14:46:59 CET 2009


May you put your code and data in the internet?
It will be easy for others to find your real problem.

----- Original Message ----- 
From: <lauramorgana at bluewin.ch>
To: <r-help at r-project.org>
Sent: Friday, February 20, 2009 7:54 PM
Subject: Re: [R] write.table


Thank you for your advice, but I didn't manage to make it work...
I tried

carichi.annui <- 
data.frame(anno,loadPTG,loadPO4,loadNT,loadNH4,loadNO3,loadBOD5,loadSiO2)

And I got this error message:

Error in data.frame(anno, loadPTG, loadPO4, loadNT, loadNH4, loadNO3,  :
  the arguments have a different numer of rows: 4, 1

If I do

sapply(carichi.annui, class)

I get:
    anno  loadPTG  loadPO4   loadNT  loadNH4  loadNO3 loadBOD5 loadSiO2
  "list"   "list"   "list"   "list"   "list"   "list"   "list"   "list"

I thought that the function as.vector() could turn a list of numbers into a 
vector... was I wrong?

----Messaggio originale----
Da: ripley at stats.ox.ac.uk
Data: 20.02.2009 12.40
A: "lauramorgana at bluewin.ch"<lauramorgana at bluewin.ch>
Copia: <r-help at r-project.org>
Oggetto: Re: [R] write.table

On Fri, 20 Feb 2009, lauramorgana at bluewin.ch wrote:

> Sorry, I'm using R 2.8.1 on Microsoft Windows XP professional 2002 Service 
> Pack 2.
> The error I get is
> Error in write.table(x, file, nrow(x), p, rnames, sep, eol,
>> na, dec, as.integer(quote),  :
>    'list' type not implemented in 'EncodeElement'
> The problem is that I can' t manage to save the dataframe...
> With other dataframe I usually have no problems!!!

What does sapply(carichi.annui, class) tell you?

It would be better to use

carichi.annui <-
data.frame(anno,loadPTG,loadPO4,loadNT,loadNH4,loadNO3,loadBOD5,loadSiO2)

as you don't need an intermediate matrix.

>
>>
>> Hello,
>> I tried to turn lists into vectors and then bind them
>> together in order to create a dataframe but if, after this, I
>> try to use the function write.table I get the following error message:
>> Error in write.table(x, file, nrow(x), p, rnames, sep, eol,
>> na, dec, as.integer(quote),  :
>>    'list' type not implemented in 'EncodeElement'
>>
>> Here is what I've done:
>> as.vector(c(unique(portate$Anno)))->anno
>> as.vector(loadListPO4)->loadPO4
>> as.vector(loadListPTG)->loadPTG
>> as.vector(loadListNT)->loadNT
>> as.vector(loadListNH4)->loadNH4
>> as.vector(loadListNO3)->loadNO3
>> as.vector(loadListBOD5)->loadBOD5
>> as.vector(loadListSiO2)->loadSiO2
>> cbind(anno,loadPTG,loadPO4,loadNT,loadNH4,loadNO3,loadBOD5,loa
>> dSiO2)->carichi
>> as.data.frame(carichi)->carichi.annui
>>
>> #if I type
>> carichi.annui
>> #I get
>>  anno   loadPTG   loadPO4   loadNT  loadNH4  loadNO3 loadBOD5 loadSiO2
>> 1 2002  3.399518  1.382235 390.6959 22.07992 256.2244
>> 492.9177 150.6505
>> 2 2003  1.559606 0.6271712 202.9181 6.198592 145.9498
>> 63.07578 68.08632
>> 3 2004  2.363862 0.9493779 292.0841 12.21207 200.2545
>> 141.0533 105.2409
>> 4 2005  1.655554 0.6570313 217.2192  6.58045 155.7393
>> 66.44154  73.0394
>> 5 2006  1.827174 0.7290634 235.7914 7.858396 166.8327
>> 79.2474 80.92576
>> 6 2007  1.742629 0.6891045 228.0253 7.130082 162.6692
>> 71.91434 77.22507
>> 7 2008 0.8382246 0.3612176 110.9079 2.024197 86.60459
>> 25.46127  32.9733
>>
>> #which looks lika a data frame
>> #And if I type
>> is.data.frame(carichi.annui)
>> # I get this:
>> [1] TRUE
>>
>> #but if I try
>> write.table(carichi.annui, "carichi.annui.lav")
>> #It doesn't work?!?!?!
>> Does someone have an explanation?
>> Thanks a lot for any help!!
>> Laura
>>
> Laura,
>
> What do you mean by "It doesn't work"?  Do you get error messages?  Or, do
> you just not get what you want?  And if so, what is that you want?
>
> Dan
>
> Daniel Nordlund
> Bothell, WA USA
>
> ______________________________________________
> 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.
>
> ______________________________________________
> 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
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