我在带有 R.NET 的 C# 网络应用程序中使用 R。当我在我的网络应用程序中添加下面的代码时,出现以下错误。但是当我在控制台应用程序中运行相同的代码时,它工作正常。我不知道为什么它在网络应用程序中不起作用。
错误信息:
An exception of type 'RDotNet.EvaluationException' occurred in RDotNet.dll but was not handled in user code
Additional information: Error: could not find function "cor"
代码:
public double Test()
{
REngine.SetEnvironmentVariables();
REngine engine = REngine.GetInstance();
if (engine.IsRunning == false)
{
engine.Initialize();
}
NumericVector group1 = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 });
engine.SetSymbol("group1", group1);
NumericVector group2 = engine.CreateNumericVector(new double[] { 29.89, 29.93, 29.72, 29.98, 30.02, 29.98 });
engine.SetSymbol("group2", group2);
var coefficientValue = engine.Evaluate("cor(group1, group2, method = c('pearson'))");
var coefficientValueNumeric = coefficientValue.AsNumeric();
double pearsonCoefficient = coefficientValueNumeric.ElementAt(0);
engine.Dispose();
return pearsonCoefficient;
}
最佳答案
我已经找到了这个问题的答案。添加 c:\Program Files\r\R-3.2.0\bin\i386 到机器或用户的 PATH 环境变量。
关于c# - R.NET 找不到函数 "cor",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43589328/