[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. -- 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. __ 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] How insert data to a column in existing csv file?
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. __ 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] 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 __ 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] How insert data to a column in existing csv file?
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Yellow Sent: Thursday, April 12, 2012 2:18 AM To: r-help@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 __ 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] How insert data to a column in existing csv file?
I would suggest using the XLConnect package so that you can read/write the Excel files directly. You can read in the files to a dataframe, make your transformations and then write the result back out to the Excel file. On Thu, Apr 12, 2012 at 11:29 AM, Nordlund, Dan (DSHS/RDA) nord...@dshs.wa.gov wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Yellow Sent: Thursday, April 12, 2012 2:18 AM To: r-help@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 __ 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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ 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] How insert data to a column in existing csv file?
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. __ 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.