Add a value or character in a particular cell (A1) in excel using R studio
1
0
Entering edit mode
3.0 years ago
sankadinesh ▴ 20

Dear All, I want to do this Add a value or character in a particular cell (e.g. A1) in excel using R. Please help

Thanks and regards, Dinesh

R studio • 1.9k views
ADD COMMENT
1
Entering edit mode

Context and effort are not clear. Please post the context of your question, expected example output and your effort.

ADD REPLY
0
Entering edit mode

Hi there, I want to add "Sample_ID" character in A1 cell, which is empty in excel sheet (attached). I want this one to be done in R

https://www.dropbox.com/s/4b17dp5sdi4hbts/Metadata1.xlsx?dl=0

Regards, Dinesh

ADD REPLY
0
Entering edit mode
## Create an empty data frame with one column, no rows, with column header "sample_ID"
df=data.frame("Sample_ID"=matrix(ncol = 1, nrow = 0))

## Write data frame as xls file to HDD
WriteXLS::WriteXLS(df,"test.xls")

Open xls file and very first cell would have name "Sample_ID".

ADD REPLY
0
Entering edit mode

Thanks for your reply. I do not want it in a new excel sheet. I want that "sample ID" in A1 cell of an existing excel sheet. How to do that ? If possible pls reply. thanks

ADD REPLY
0
Entering edit mode

I agree with @ Michael Dondrup below. Please do as Michael Dondrup suggested.

ADD REPLY
0
Entering edit mode

How many sheets are we talking, I don't really see your point here. A single file: open the file in Excel (or OpenOffice/ LibreOffice Calc, Numbers, ...), edit the column headers in the way you want, save, done. If using R for doing that, it would be pretty unwise to overwrite your original file because you might corrupt it.

ADD REPLY
1
Entering edit mode
3.0 years ago
Michael 55k

I am not going to open that excel sheet, but I think it is much easier to simply enter the text into the sheet directly. That said, you can certainly import from excel into R directly using library readxl. See https://readxl.tidyverse.org/ for how to read and write data to excel formats and watch out for limitations (multiple sheets (works but need some additional commands) , macros, functions, ...) There is also an Excel import wizard in R-studio. Once the data is imported, you can change column names as you like. I am not 100% sure but I suspect that you will loose any formula and formatting contained in the original sheet.

Unless you want to further process the data in R it is too much overhead.

ADD COMMENT

Login before adding your answer.

Traffic: 1791 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6