3

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.

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

The following link is not working, is the createDataFrame() method still working?
Could you post an example of how you managed that? If possible, showing the imports, because those two abstractions are quite confusing sometimes. Thanks in advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.