提问人:Hack-R 提问时间:2/12/2015 最后编辑:Hack-R 更新时间:2/12/2015 访问量:188
如何通过 rinruby 在 Ruby 中将 R 中的值放入
How to puts value from R in Ruby via rinruby
问:
我需要能够在 R 中访问在 R 代码中创建的值,如本示例所示。
require "rinruby"
#Set all your variables in Ruby
n = 10
beta_0 = 1
beta_1 = 0.25
alpha = 0.05
seed = 23423
R.x = (1..n).entries
#Use actual R code to perform the analysis
R.eval <<EOF
set.seed(#{seed})
y <- #{beta_0} + #{beta_1}*x + rnorm(#{n})
fit <- lm( y ~ x )
est <- round(coef(fit),3)
pvalue <- summary(fit)$coefficients[2,4]
EOF
puts pvalue
但是我收到错误:
test.rb:21:in `<main>': undefined local variable or method `pvalue' for main:Object (NameError)
答:
1赞
scottb
2/12/2015
#1
将最后一行更改为:
puts R.pull("pvalue")
评论
0赞
Hack-R
2/12/2015
成功了!谢谢!现在你提到了 J. Statistical Software 文章中的 pull 方法,我看到了它
0赞
PhilT
12/21/2015
另一种选择是R.pvalue
评论