问题描述
使用 R.NET 创建S4 object
(mirt
包中函数的输出.
While using R.NET for creating an S4 object
( an output of a function from the mirt
package.
engine.Evaluate("library(mirt); data(LSAT6); x=mirt(LSAT6,1)");
S4Object Convertedinput = inputtoCsharp.AsS4();
我需要在消息框中查看x的输出(x的所有插槽).
I need to to see the output of x (all the slots of x) into a message box.
我该怎么做?
因为没有方法可以执行以下操作:
because there is no method which does something like this:
int[] resp_c = new int [] {1,1,1,1};
**IntegerVector resp_cR = engine.CreateIntegerVector(resp_c);**
engine.SetSymbol("resp_c", resp_cR);
engine.Evaluate("ff=fscores(x, response.pattern=resp_c)");
对整数向量完成上述操作.我需要对R中的S4 object
进行仿真.
above thing is done for the integer vector. I need to emulate same for the S4 object
in R.
我该怎么做?
推荐答案
不是完全确定我理解您的请求,但是下面的示例代码应该会有所帮助.也可以从 R.NET支持github存储库中使用,方法ReproStackOverflow_34355201
在/ReproUsers/Program.cs文件中.为了将来参考,写在提交43a8ec3
Not fully sure I understand your request, but the sample code below should help. It is also available from An R.NET support github repo, method ReproStackOverflow_34355201
in file /ReproUsers/Program.cs . For future reference, written at commit 43a8ec3
engine.AutoPrint = true;
//samples taken from ?fscores man page in package mirt
engine.Evaluate("library(mirt)");
// 'Science' is a prepackage sample data in mirt; you can use 'engine.CreateDataFrame' in C# to create your own if need be.
engine.Evaluate("mod <- mirt(Science, 1)");
engine.Evaluate("class(mod)");
S4Object modcs = engine.GetSymbol("mod").AsS4();
IDictionary<string, string> slotTypes = modcs.GetSlotTypes();
if (slotTypes.Keys.Contains("Fit"))
{
GenericVector fit = modcs["Fit"].AsList();
// should check logLik in fit.Names;
double logLik = fit["logLik"].AsNumeric()[0];
}
engine.Evaluate("tabscores <- fscores(mod, full.scores = FALSE)");
engine.Evaluate("head(tabscores)");
engine.Evaluate("class(tabscores)");
NumericMatrix tabscorescs = engine.GetSymbol("tabscores").AsNumericMatrix();
这篇关于如何使用RdotNet创建S4对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!