Column of unwanted numbers in write.xlsx

Asked

Viewed 98 times

2

I am saving a data frame in excel spreadsheet with the following command:

library(xlsx)

write.xlsx(df, "buildingTEPT.xlsx", sheetName = "TEPT", showNA = F, col.names = T)

It turns out that the spreadsheet already has a column that enumerates my sample. However, R is adding another column. And this is repeated every time you save. How do I not add this column, remaining only with others?

Foto de como ficou no EXCEL

  • Excuse the ignorance, but I could not know which programming language you are using...

  • In "R" Rodrigo Tognin!

  • Gleidson, I think it would be interesting to paste some part of the code that is generating the spreadsheet so that we can try to identify the reason why it is duplicating the first column...

  • Well. the spreadsheet was created in Excel and was imported into R with: excel_sheets('buildingTEPT.xlsx') df <- read_excel('buildingTEPT.xlsx', sheet = "TEPT") ## Then analyses were done on some data and the re-placement of some missings values. At the end, it was exported with the above line and that’s it! This column appears without header.. only numbers

  • This function is explained in the R documentation: https://www.rdocumentation.org/packages/xlsx/versions/0.6.1/topics/write.xlsx

1 answer

3


The problem occurs because the function write.xlsx comes with the parameter TRUE in the argument row.names. So you must do:

library(xlsx)

write.xlsx(df, "buildingTEPT.xlsx", sheetName = "TEPT", showNA = F, col.names = T, row.names = FALSE)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.