Add a value or character in a particular cell (A1) in excel using R studio
1
0
Entering edit mode
10 weeks ago

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 • 527 views
1
Entering edit mode

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

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

Regards, Dinesh

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".

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

0
Entering edit mode

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

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.

1
Entering edit mode
10 weeks ago

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.