在Ruby中使用R的最佳方式 [英] Best way to use R in Ruby

查看:82
本文介绍了在Ruby中使用R的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要在Ruby中可视化我的一些统计计算。



我的问题是,我找不到合适的gem。



rsruby似乎并不是最新的,我无法在Ruby 1.9.2中安装它。



你知道如何在Ruby中运行R命令吗?

解决方案

我刚刚看到这篇文章,并认为我应该评论因为我相当广泛地使用R.如果您来自R背景,我发现的最佳宝石是 Rinruby

一>。这很奇妙的原因是因为你不用ruby来解释命令,你使用真正的R代码。例如:

  requirerinruby
#设置Ruby中的所有变量
n = 10
beta_0 = 1
beta_1 = 0.25
alpha = 0.05
seed = 23423
Rx =(1..n).entries
#使用实际的R代码(#{seed})
y < - #{beta_0} +#{beta_1} * x + rnorm(# (fitf),3)
pvalue< - 概要(拟合);"系数> 2,4]
EOF

在上面列出的Rinruby网站上,有一些很棒的例子让你开始。希望这有助于。




I want to visualize some of my statistical caluclations in Ruby.

My problem is, that I can't find the right gem for that.

rsruby doesn't seem to be up-to-date and I can't install it in Ruby 1.9.2.

Do you know a way how to run the R commands in Ruby?

解决方案

I just saw this post and thought I should comment since I use R pretty extensively. If you are coming from an R background the best gem I have found is Rinruby. The reason it is fantastic is because you don't interpret the commands in ruby, you use actual R code. For example:

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

On the Rinruby website I listed above there are some fantastic examples to get you started. Hope this helped.

-Sean

这篇关于在Ruby中使用R的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆