Fahim Ahmad
Fahim Ahmad

Reputation: 35

Export result R data frame into an Excel file

can anyone help me with how to export the result of comparedf() from the arsenal package to an Excel file?

Here is my script:

diff <- diffs(comparedf(mtcars[1:10, ], mtcars[2:11,]))
openxlsx::write.xlsx(diff, "diff.xlsx")

The error message is Error in is.nan(tmp) : default method not implemented for type 'list'

Upvotes: 2

Views: 2803

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 388797

diffs function returns certain columns of class 'AsIs' which is of type list.

unlist those columns into a vector before writing them to Excel.

diff[] <- lapply(diff, function(x) if(class(x) == 'AsIs') unlist(x) else x)
openxlsx::write.xlsx(diff, "diff.xlsx")

Upvotes: 2

Related Questions