1

I am trying to write multiple dataframe to a single csv formated file but each in a different sheet of the excel file:

write.csv(dataframe1, file = "file1.csv",row.names=FALSE)
write.csv(dataframe2, file = "file2.csv",row.names=FALSE)

is there any way to specify the sheet along with the csv file in this code and write them all in one file?

thank you in advance,

5
  • 3
    with package WriteXLS ? csv is a text file, I really don't think you can have sheets in csv... Commented Nov 18, 2014 at 8:44
  • @CathG :yeah right sorry,i meant one excel file with a csv format Commented Nov 18, 2014 at 8:50
  • @f.a Do you mean to collapse all dataframes into 1 dataframe, then output into 1 CSV file? Commented Nov 18, 2014 at 8:51
  • @zx8754, No I mean to write each dataframe in each sheet of the csv formated excel file Commented Nov 18, 2014 at 9:02
  • 4
    WriteXLS is the answer. There is no such thing as Excel file with CSV sheets... Commented Nov 18, 2014 at 9:11

2 Answers 2

4

This is not possible. That is the functionality of csv to be just in one sheet so that you can view it either from notepad or any other such software. If you still try to write it would get over ridden. Just try to open a csv and open a new sheet and just write some values and save it. The values which were already there is erased. one excel file in csv format can have only one sheet.

Sign up to request clarification or add additional context in comments.

2 Comments

yeah, right, thank you @Arun Raja , as zx87546 and CathG commented, I could have multiple sheet in a single excel file through WriteXLS
XLConnect is better. Try that. You can define the number of sheets while writing. getsheets() gives the number of sheets while reading it back.
0

The xlsx and XLConnect packages will do the trick as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.