民间,
我有最简单的代码,我为测试R.NET而构建,但在调试时却一直出错。我填充dictionary
,然后构建一个简单的R data frame
。填充字典时不显示代码。虽然调试我这样做了,但这是正确的。
C#代码:
Dictionary<string, List<double>> LiqProductionData = new Dictionary<string, List<double>>();
Engine.SetEnvironmentVariables();
REngine engine = REngine.GetInstance();
var DataFrame_Columns = new List<IEnumerable>(LiqProductionData.Values); //column data
var DataFrame_Colnames = new List<string>(LiqProductionData.Keys); // column header
var DataFrame_R = engine.CreateDataFrame(DataFrame_Columns.ToArray(), DataFrame_Colnames.ToArray());
engine.SetSymbol("ProdData", DataFrame_R);
engine.Evaluate("source('D:/OFM_R/OFM_R_Example.R')"); // Run the "R" script
var X = engine.GetSymbol("newProdData").AsNumericMatrix();
RScript代码:
setwd("D:/OFM_R")
ProdData <- as.matrix(DataFrame_R) #converting the DATA Frame from OFM into R Matrix ProdData
newProdData <- ProdData*100
以下是错误:
as.matrix(DataFrame_R)出错:找不到对象'DataFrame_R' {“as.matrix(DataFrame_R)出错:找不到对象'DataFrame_R'\ n”}
答案 0 :(得分:0)
知道了。我在engine.setsymbol
声明中犯了一个错误。
它应该修改为:
engine.SetSymbol("DataFrame_R", DataFrame_R);