This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Add a value or character in a particular cell (A1) in excel using R studio

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

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

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

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

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 answer

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.

Log in to answer this question.