I'm using the write_xlsx command to export data from R to excel,
Here is the data frame that I have,
>df
X1
A 76
B 78
C 10
Using ,
write_xlsx(df, "../mydata.xlsx")
gives the following output in excel,
>df
1 76
2 78
3 10
The column names appear in the xlsx file but the index of each row isn't printed. Is there any way to print the row index in the excel file?
Use below function with argument row.names = TRUE
library(xlsx)
write.xlsx(df, "../mydata.xlsx", sheetName = "Sheet1", col.names = TRUE, row.names = TRUE)