exporting to excel results from deaR

I am new using R and Im a little desperate. After a week of fighting to do a DEA, now I need to
to export my DEA results from R to Excel.
class(result)
[1] "dea"

Package xlsx gives me error with java:
library("xlsx")
Error: package or namespace load failed for ‘xlsx’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: No CurrentVersion entry in Software/JavaSoft registry! Try re-installing Java and make sure R and Java have matching architectures.

And openslsx gives me the following error:
write.xlsx(result, "result2.xlsx")
Error in as.data.frame.default(x, stringsAsFactors = FALSE) :
cannot coerce class ‘"dea"’ to a data.frame

Thank you

Celia

Hi,

Welcome to the RStudio community!

The Java error can be annoying and many people at some point run into issues with it.

First of all, have you installed Java? If not, do that first (this is not an R package, but separate software):
https://java.com/en/download/help/download_options.xml

Then install rJava too in R:

install.packages("rJava")

Then try again.

Second, I don't know DEA, but installing the rDEA package and running the example it seems that a DEA object is a list and not a data frame. You can't write list like that to excel, or transform it into a data frame. You need to parse the different parts of the list into a dataframe manually (meaning coding it yourself) then save it.

Having said that, I see that the lists have similar lengths, so it actually is possible writing it to excel without extra transformations (though all will be put together in one sheet). Here is an example (taken from the package's examples):

library(xlsx)
library(rDEA)

data("hospitals", package="rDEA")

## inputs and outputs for analysis
Y = hospitals[c('inpatients', 'outpatients')]
X = hospitals[c('labor', 'capital')]
W = hospitals[c('labor_price', 'capital_price')]

## Naive input-oriented DEA score for the first 20 firms under variable returns-to-scale
firms=1:20
di_naive = dea(XREF=X, YREF=Y, X=X[firms,], Y=Y[firms,], model="input", RTS="variable")

write.xlsx(di_naive, "test.xlsx")

Hope this helps,
PJ

1 Like

Hi,

Thanks a lot.

  1. I had installed Java, as separate software.

  2. I try to intall rJava but trying to load it, again the error

library(rJava)
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: No CurrentVersion entry in Software/JavaSoft registry! Try re-installing Java and make sure R and Java have matching architectures.

So, when I try to load slsx, again the error
library(xlsx)
Error: package or namespace load failed for ‘xlsx’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: No CurrentVersion entry in Software/JavaSoft registry! Try re-installing Java and make sure R and Java have matching architectures.

Thanks

Celia

You also have to set the path in R to java.

See this post:

Hope this helps,
PJ

Thank you very much!!
I got it.
I installed Java offline for 64bits (jre-8u241-windows-x64.exe), previously closing all applications.
Then in R
install.packages("rJava")
library("rJava")
install.packages("xlsx")
library("xlsx")

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.