2014-03-02 63 views
0

我怎樣才能讀取R到.net的樹值?我試過這種方法,但它返回我空R.net閱讀樹

engine.Evaluate("data=read.spss(file='C:/dev/Anomaly/Vorselaar2011D.sav', to.data.frame=TRUE)"); 
engine.Evaluate("data$timestamp<-as.Date(as.POSIXct(data$timestamp, origin = \"1582-10-14\", tz = \"GMT\"))"); 
var data =engine.Evaluate("treeElect<-tree(Electricity_kWh~Water_lh+Day_of_Week+TempOut_mean+GasM3h, data=data)"); 
var dataset = engine.Evaluate("treeElect").AsDataFrame(); 

當我R中控制檯做到這一點我可以看到這個輸出

> treeElect 
node), split, n, deviance, yval 
     * denotes terminal node 

1) root 365 1006000 146.40 
    2) Water_lh < 214 123 84580 85.46 
    4) GasM3h < 64 94 10540 77.95 * 
    5) GasM3h > 64 29 51550 109.80 
     10) Day_of_Week < 5 5 9028 186.30 * 
     11) Day_of_Week > 5 24 7148 93.86 * 
    3) Water_lh >0 177.40 
    6) Water_lh < 582.25 90 44470 154.70 
     12) GasM3h < 87.75 75 20880 149.00 * 
     13) GasM3h > 87.75 15 8857 183.30 * 
    7) Water_lh > 582.25 152 113800 190.90 
     14) GasM3h < 54.4 72 29300 175.30 * 
     15) GasM3h > 54.4 80 51360 204.90 
     30) Day_of_Week < 1.5 22 5340 231.50 * 
     31) Day_of_Week > 1.5 58 24540 194.80 * 

回答

1

下似乎得到我的數據幀你似乎正在尋求。即使在R中,我也沒有使用您提供的代碼來獲取數據框(如果我們正在討論相同的樹函數,treeElect不是數據框)。請注意,我使用R.NET的最新開發分支測試了代碼示例;您可能必須對R.NET 1.5.5使用不同的命令,下面進行了評論。

private static void ReproTreeEnquiry(REngine e) 
{ 
    e.Evaluate("library(tree)"); 
    var irtr = e.Evaluate("ir.tr <- tree(Species ~., iris)"); 
    // the following will print a human readable tree to the console output 
    e.Evaluate("print(ir.tr)"); 
    var aList = irtr.AsList(); // May work only with the latest dev code 
    // for R.NET 1.5.5 you may need to do instead: 
    aList = e.Evaluate("as.list(tree(Species ~., iris))").AsList(); 
    var theDataFrame = aList[0].AsDataFrame(); 
    // Further processing of theDataFrame, etc. 
}