I was working with some excel files with a lot of data. And by hand it is impossible to handle them. So they are now converted to .csv. With headers above the columns, like: Data1, Data2, Data3 But now I needed to calculate the log2 value of Data1 and place the result under Data2. I can't find how to do that. Does anyone else know? I have the log2 values, but how do I get then inside the .csv file under Data2? I already tried write.table(), buy that wasn't it. And I am kinda stuck on this now..... -- View this message in context: http://r.789695.n4.nabble.com/How-insert-data-to-a-column-in-existing-csv-file-tp4551327p4551327.html Sent from the R help mailing list archive at Nabble.com.
Hi, You can use write.table with Append = TRUE to keep on writing in the same csv file, but I don't know how to write in an specific cell of your csv file. http://stat.ethz.ch/R-manual/R-devel/library/utils/html/write.table.html write.table (data, file = "example.csv", sep = ";", col.names = NA, append TRUE, dec =",") I think the best thing to do once you have imported your data into R is to create a new csv file and write in it the table you need. Hope it helps, R -- View this message in context: http://r.789695.n4.nabble.com/How-insert-data-to-a-column-in-existing-csv-file-tp4551327p4551441.html Sent from the R help mailing list archive at Nabble.com.
David Winsemius
2012-Apr-12 12:16 UTC
[R] How insert data to a column in existing csv file?
On Apr 12, 2012, at 5:18 AM, Yellow wrote:> I was working with some excel files with a lot of data. > And by hand it is impossible to handle them. > So they are now converted to .csv. > > With headers above the columns, like: > Data1, Data2, Data3 > > But now I needed to calculate the log2 value of Data1 and place the > result > under Data2. > I can't find how to do that.First you need to explain more clearly what you mean by "place the result under Data2". Is this a display concern? Or are you trying to interleave rows of original data and logged data using a column organization? Why only Data2? What should go in the rows for Data1 and Data3? ? What is the goal of this effort?> Does anyone else know? > > I have the log2 values, but how do I get then inside the .csv file > under > Data2?Post some sample code that constructs the data.frames and the code you used.> > I already tried write.table(), buy that wasn't it. > And I am kinda stuck on this now.....-- David Winsemius, MD West Hartford, CT
Nordlund, Dan (DSHS/RDA)
2012-Apr-12 15:29 UTC
[R] How insert data to a column in existing csv file?
> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Yellow > Sent: Thursday, April 12, 2012 2:18 AM > To: r-help at r-project.org > Subject: [R] How insert data to a column in existing csv file? > > I was working with some excel files with a lot of data. > And by hand it is impossible to handle them. > So they are now converted to .csv. > > With headers above the columns, like: > Data1, Data2, Data3 > > But now I needed to calculate the log2 value of Data1 and place the > result > under Data2. > I can't find how to do that. > Does anyone else know? > > I have the log2 values, but how do I get then inside the .csv file > under > Data2? > > I already tried write.table(), buy that wasn't it. > And I am kinda stuck on this now..... > >In the absence of a reproducible example, we can only guess. My guess is that you should read the csv file into a data frame, add or modify your variable(s), then write out a new csv file. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204
Hi everyone, I read your messages and I tried some things out. The Data2 is filled with NA. So what I did was: NameFile.csv$Data2[is.na(NameFile.csv$Data2)] = log2Values And now it worked. :) Seems like I needed to replace it, and not only write it. Thanks. -- View this message in context: http://r.789695.n4.nabble.com/How-insert-data-to-a-column-in-existing-csv-file-tp4551327p4552463.html Sent from the R help mailing list archive at Nabble.com.