hallo, i have a problem by writing a csv file the first colum is filled with index numbers from 1 to n. i have to unique two csv files once a week while one file is always the same. can anybody tell me, how to write the dataset into a csv file without the first row of the indexnumbers. x[,-1] does not wok as it eliminates the first "interesting" colum. col.names is not accepted by r (do i habe to start a package first? which one?) thx sven [[alternative HTML version deleted]]
On Thu, 2005-11-24 at 17:00 +0100, Sven Schaltenbrand wrote:> hallo, > > i have a problem by writing a csv file > the first colum is filled with index numbers from 1 to n. > i have to unique two csv files once a week while one file is always the > same. > can anybody tell me, how to write the dataset into a csv file without the > first row of the indexnumbers. > x[,-1] does not wok as it eliminates the first "interesting" colum. > col.names is not accepted by r (do i habe to start a package first? which > one?) > > thx > > sven > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-develThis isn't a R-Devel related question, it would have been better sent to R-Help: https://stat.ethz.ch/mailman/listinfo/r-help Also, you are asked to read the docs for the functions you are having problems with. The answer is in ?write.csv and the argument row.names. Setting this to FALSE gives you your desired behaviour, e.g.:> ?write.csv > data(iris) #example data > write.csv(iris, row.names = FALSE) > write.csv(iris, row.names = TRUE)As I didn't specify a filename as the file argument, the results are displayed at the console. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way [W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
I don't understand very well if your problem is rownames or column names, but what you want must be : row.names=FALSE and/or col.names=FALSE, which are arguments of the function 'write.table()' don't think you need to load any particular package for that. see also : ---------------------------------------------------------------------------------------------------- 'write.csv' and 'write.csv2' provide convenience wrappers for writing CSV files. They set 'sep', 'dec' and 'qmethod', and 'col.names' to 'NA' if 'row.names = TRUE' and 'TRUE' otherwise. ---------------------------------------------------------------------------------------------------- from ?write.table hope this helps. Florence. On 11/24/05, Sven Schaltenbrand <sven@schaltenbrand.de> wrote:> > hallo, > > i have a problem by writing a csv file > the first colum is filled with index numbers from 1 to n. > i have to unique two csv files once a week while one file is always the > same. > can anybody tell me, how to write the dataset into a csv file without the > first row of the indexnumbers. > x[,-1] does not wok as it eliminates the first "interesting" colum. > col.names is not accepted by r (do i habe to start a package first? which > one?) > > thx > > sven > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >[[alternative HTML version deleted]]
If you don't want the row names, as 'write.csv()' writes out by default, try write.table(<object>, file = "myfile.csv", sep = ",", row.names = FALSE) -roger Sven Schaltenbrand wrote:> hallo, > > i have a problem by writing a csv file > the first colum is filled with index numbers from 1 to n. > i have to unique two csv files once a week while one file is always the > same. > can anybody tell me, how to write the dataset into a csv file without the > first row of the indexnumbers. > x[,-1] does not wok as it eliminates the first "interesting" colum. > col.names is not accepted by r (do i habe to start a package first? which > one?) > > thx > > sven > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Upon replying to this email, I took a look at 'write.csv()' and noticed something interesting. I remember there being a discussion sometime in the past about letting 'write.csv()' accept the 'row.names' argument. However, I get the following error: > write.csv(airquality, file = "myfile.csv", row.names = F) Error in write.table(airquality, file = "myfile.csv", row.names = F, col.names = NA, : col.names = NA makes no sense when row.names = FALSE > In 'write.csv()' there is rn <- Call$row.names Call$col.names <- if (is.logical(rn) && !rn) TRUE but is.logical(rn) is always FALSE because even if 'row.names' is specified (non-NULL), it is of class "name". Perhaps something like rn <- eval(Call$row.names) would suffice? I can't tell if that would break anything. -roger Sven Schaltenbrand wrote:> hallo, > > i have a problem by writing a csv file > the first colum is filled with index numbers from 1 to n. > i have to unique two csv files once a week while one file is always the > same. > can anybody tell me, how to write the dataset into a csv file without the > first row of the indexnumbers. > x[,-1] does not wok as it eliminates the first "interesting" colum. > col.names is not accepted by r (do i habe to start a package first? which > one?) > > thx > > sven > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >