Python Jupyter RMagic不';t返回交互式R输出
根据图,应该可以看到交互式R输出,如下所示:Python Jupyter RMagic不';t返回交互式R输出,python,r,jupyter,rpy2,Python,R,Jupyter,Rpy2,根据图,应该可以看到交互式R输出,如下所示: %%R X=c(1,4,5,7) Y = c(2,4,3,9) summary(lm(Y~X)) 它应该产生这样的结果: Call: lm(formula = Y ~ X) Residuals: 1 2 3 4 0.88 -0.24 -2.28 1.64 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept)
%%R
X=c(1,4,5,7)
Y = c(2,4,3,9)
summary(lm(Y~X))
它应该产生这样的结果:
Call:
lm(formula = Y ~ X)
Residuals:
1 2 3 4
0.88 -0.24 -2.28 1.64
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.0800 2.3000 0.035 0.975
X 1.0400 0.4822 2.157 0.164
Residual standard error: 2.088 on 2 degrees of freedom
Multiple R-squared: 0.6993,Adjusted R-squared: 0.549
F-statistic: 4.651 on 1 and 2 DF, p-value: 0.1638
但是,尽管能够使用从R返回美观的图形,但是从摘要
返回的R交互输出不会返回
我可以通过以下方式解决这个问题:
In [75]: %%R -o return_value
: X = c(1,4,5,7)
: Y = c(2,4,3,9)
: return_value = summary(lm(Y~X))
然后按如下方式打印返回值(尽管输出看起来很糟糕,因为每个输出行之间都有空行):
是文件不正确,还是我做错了什么
In [86]: print(return_value)
Call:
lm(formula = Y ~ X)
Residuals:
1 2 3 4
0.88 -0.24 -2.28 1.64
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.0800 2.3000 0.035 0.975
X 1.0400 0.4822 2.157 0.164