[R] Problem in appending a row to *.csv file
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.98333 and when I try to append another column for this file its writing like "","max","min","avg" "1",22,7,12.98333 "","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@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.
Re: [R] Problem in appending a row to *.csv file
For some clever reason, write.csv won't let you set col.names argument to FALSE, but you can use it with write.table using sep=",". A self-contained, minimal, and working example: write.csv(matrix(1:10,2,5), "test.csv") write.table(matrix(11:20,2,5), "test.csv", sep=",", append=TRUE, col.names=FALSE) Regards, KK On Mon, Feb 9, 2009 at 12:17 PM, 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.98333 > > and when I try to append another column for this file its writing like > > "","max","min","avg" > "1",22,7,12.98333 > "","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@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. > [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Problem in appending a row to *.csv file
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 8Aug 34 35854135 9 Sept 35 74783935 10 Sept 36 45968236 11 Sept 37 60956736 12 Sept 38 97947536 13 Sept 39 83718936 > tail( rbind(DF, c("Aug", 36, 555, 44)) ) Month Week Estpassage MedFL 9 Sept 35 74783935 10 Sept 36 45968236 11 Sept 37 60956736 12 Sept 38 97947536 13 Sept 39 83718936 14 Aug 3655544 -- 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.98333 and when I try to append another column for this file its writing like "","max","min","avg" "1",22,7,12.98333 "","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@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@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.