silicoflagellate
silicoflagellate

Reputation: 13

Is there a package in R that can be used to delete multiple columns from an excel document?

It seems xlsx and openxlsx do not have this capability. I am writing a loop with the hopes that it will delete a row if a value in a certain column exceeds zero. My only problem is my own inability to find a package with a command that can do this.

Upvotes: 0

Views: 584

Answers (1)

M. Siwik
M. Siwik

Reputation: 497

Here you have an example from openxlsx package

https://rdrr.io/cran/openxlsx/man/deleteData.html

for deleting data. But you need to detect by yourselft columns, or rows which you want to delete.

wb <- createWorkbook()

addWorksheet(wb, "Worksheet 1")
x <- data.frame(matrix(runif(200), ncol = 10))
writeData(wb, sheet = 1, x = x, startCol = 2, startRow = 3, colNames = FALSE)

## delete some data
deleteData(wb, sheet = 1, cols = 3:5, rows = 5:7, gridExpand = TRUE)
deleteData(wb, sheet = 1, cols = 7:9, rows = 5:7, gridExpand = TRUE)
deleteData(wb, sheet = 1, cols = LETTERS, rows = 18, gridExpand = TRUE)
## Not run: 
saveWorkbook(wb, "deleteDataExample.xlsx", overwrite = TRUE)

Upvotes: 1

Related Questions