Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Export Large data into Excel

Tags:

r

excel

I am using sink() function for printing R output to excel/text file. my program output is too large. I found at the end of Excel/text output file a message

[ reached getOption("max.print") -- omitted 5326 rows ] 

Also I have more than one large outputs to print. I also want them on separate (different) sheets of one excel file .

Actually, the output comes in matrix form, as the value of loop increases, the rows and columns of square matrices also increases. the function append does not work due to difference of rows and columns number. to avoid this error I used if condition and deal separately using rbind for similar matrices. But there is more than 5 thousand iteration through double loop (and the method also repeats), so it is impossible to write 1000's of if and rbind conditions and save them into separate sheets and files.

like image 904
Zaheer Abbas Avatar asked May 17 '26 01:05

Zaheer Abbas


1 Answers

if you don't want a csv you can use package xlsx and it is pretty easy to save multiple sheets e.g.

df1 <- data.frame(x=1:100, y=1:100)   # make data
df2 <- data.frame(x=1:1000, y=1:1000) 

library(xlsx)

wb <- createWorkbook()         # create blank workbook
sheet1 <- createSheet(wb, sheetName="mysheet1") # create different sheets
sheet2 <- createSheet(wb, sheetName="mysheet2")
addDataFrame(df1, sheet1)  # add data to the sheets
addDataFrame(df2, sheet2)
saveWorkbook(wb, "mysheets.xlsx")  # write the file with multiple sheets
like image 167
user1317221_G Avatar answered May 18 '26 18:05

user1317221_G



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!