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
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")
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.
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")