Domanda

I can use an R environment from Java using JRI, but I'm wondering if there's a better way to create data frames than the following (using Scala syntax for arrays):

r.assign("predictor1", Array(1,2,3,1))
r.assign("predictor2", Array("a","b","a","c"))
r.assign("class", Array("y","n","y","n"))
r.eval("df = data.frame(predictor1=predictor1, predictor2=predictor2, class=class)")

Besides being a bit cumbersome, note how I've just polluted the global namespace and accidentally clobbered the standard class function.

Attempting to remedy the latter two problems, I also tried first creating an empty data.frame and then calling r.assign("df$predictor1", Array(1,2,3,1)), but that doesn't work - it assigns to a variable named df$predictor.

È stato utile?

Soluzione

Turns out JRI has two levels of abstraction (JRI and REngine) and I was looking at the wrong one (JRI). REXP in REngine has a createDataFrame() method:

http://rforge.net/org/doc/org/rosuda/REngine/REXP.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top