Reputation: 1
I have a data frame, with some of the values being NA. When I tried to export the data frame to excel using WriteXLS package, the NA values disappeared (but not the NaN values). Is there a way to explicitly display "NA" in the spreadsheet for my NA values?
A workable example can be
x <- c(NA, 8, 5)
l <- c("ab", "cd", "ef")
s <- c(8, NA, 5)
df = data.frame(x, l, s)
write.xlsx(df,"path/to/file/test.xlsx")
Thank you very much!
Edited: I originally asked about the usage of the package WriteXLS, since I didn't want to install two packages (rJava+xlsx), I got WriteXLS. However, I think somebody else using xlsx will benefit from @PavoDive's answer, so I'll just add the following example data frame
x <- c(NA, 8, 5)
l <- c("ab", "cd", "ef")
s <- c(8, NA, 5)
df = data.frame(x, l, s)
library(WriteXLS)
WriteXLS("df", "df.xls")
Upvotes: 0
Views: 907
Reputation: 6496
You need to set to TRUE
the showNA
argument:
library(xlsx)
write.xlsx(df,"path/to/file/test.xlsx",append=T,showNA=T)
Upvotes: 1