[R] Problem in appending a row to *.csv file

David Winsemius dwinsemius at comcast.net
Mon Feb 9 15:26:49 CET 2009


Looking at your question, I found myself wondering if you really  
wanted to do this at all. It appeared so much like inefficient habits  
acquired in the years of BASIC and Excel use. If you are interested in  
storing a dataframe to disk and then bringing it back into an R  
session, then the save and load functions are more appropriate.

Append works on vectors (and apparently on lists although the append  
help page does not document that behavior), but will probably not have  
the desired effect on dataframes.

Look instead at the rbind function if you are interested in adding row- 
wise to a dataframe.

 > tail(DF)
    Month Week Estpassage MedFL
8    Aug   34     358541    35
9   Sept   35     747839    35
10  Sept   36     459682    36
11  Sept   37     609567    36
12  Sept   38     979475    36
13  Sept   39     837189    36
 > tail( rbind(DF, c("Aug", 36, 555, 44)) )
    Month Week Estpassage MedFL
9   Sept   35     747839    35
10  Sept   36     459682    36
11  Sept   37     609567    36
12  Sept   38     979475    36
13  Sept   39     837189    36
14   Aug   36        555    44

-- 
David Winsemius

On Feb 9, 2009, at 5:17 AM, venkata kirankumar wrote:

> Hi all,
> I am new to R-project
> I have a problem when when ever I am going to append a row in a  
> *.csv file
> that is
> in R-project I created one dataframe and I saved it in "res.csv"   
> and again
> I got some results in dataframe with same column names and i tried  
> to append
> in a new row of same  "res.csv"  file but its appending again with
> columnnaes like
>
>
>
> first time when i created the  csv file
>
> "","max","min","avg"
> "1",22,7,12.9833333333333
>
> and when I try to append another column for this file its writing like
>
> "","max","min","avg"
> "1",22,7,12.9833333333333
> "","max","min","avg"
> "1",19,7,12.9918699186992
>
>
> can any one suggest how to solve this problem
> and how can I save new rows without taking column names
>
>
> and also i tried with    "append()"  function to append to  
> dataframes then
> also its giving the same result
>
> thanks in advance
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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