通过JRI从Java创建R中的data.frames(Creating data.frames in R from Java via JRI)

编程入门 行业动态 更新时间:2024-10-25 01:29:26
通过JRI从Java创建R中的data.frames(Creating data.frames in R from Java via JRI)

我可以使用JRI使用Java的R环境,但我想知道是否有更好的方法来创建数据帧而不是以下(使用数组的Scala语法):

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

除了有点麻烦之外,请注意我是如何污染全局命名空间并意外地破坏了标准class函数。

为了解决后两个问题,我还尝试首先创建一个空的data.frame,然后调用r.assign("df$predictor1", Array(1,2,3,1)) ,但这不起作用 -它分配给名为df$predictor 。

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.

最满意答案

事实证明JRI有两个抽象层次(JRI和REngine),而我正在寻找错误的抽象层次(JRI)。 REngine中的REXP有一个createDataFrame()方法:

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

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

更多推荐

本文发布于:2023-07-30 08:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336726.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Java   JRI   data   Creating   frames

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!