我需要能够在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)
答案 0 :(得分:1)
将您的最后一行更改为:
puts R.pull("pvalue")