如何在 R.net 中创建命名列表成员对象?

how can I create Named List Members object in R.net?

如何在 R.NET 中创建 "Named List Members"? R 代码如下所示:

odpar <- list(mean = c(-1.5, 0, 1.5), var = c(0.5, 0.6, 0.8)) 

你可以这样做

var engine = this.Engine;
var list = new GenericVector(engine, 2);
// odpar <- list(mean = c(-1.5, 0, 1.5), var = c(0.5, 0.6, 0.8)) 
list[0] = engine.CreateNumericVector(new[] { -1.5, 0, 1.5 });
list[1] = engine.CreateNumericVector(new[] { 0.5, 0.6, 0.8 });
list.SetNames("mean", "var");
engine.SetSymbol("TestListSetNames", list);
var listNames = engine.Evaluate("names(TestListSetNames)").AsCharacter().ToArray();
Assert.AreEqual("mean", listNames[0]);
Assert.AreEqual("var", listNames[1]);

或者,如果您的列表可以创建为数据框(与列表密切相关),您可以按照 this post, creating-a-data-frame-using-r-net

链接中提供的示例进行操作