[英]R.net error during evaluation - “subscript out of bounds”
I am getting "subscript out of bounds" error when I run R script via R.net (input data from C# code). 通过R.net(来自C#代码的输入数据)运行R脚本时,出现“下标超出范围”错误。 Strangely if I run the Rscript when same input data is provided by excel, it runs fine!
奇怪的是,如果我在excel提供相同的输入数据的情况下运行Rscript,它运行良好! Any ideas on why it would happen?
关于为什么会发生的任何想法? I am sending "vardata" from C# code.
我正在从C#代码发送“ vardata”。
* *
***Error in my.data.var.mat.1st[Pos.loc] <- my.data.var.1st :
subscript out of bounds***
* *
Here is the code and associated information. 这是代码和相关信息。
vardata <- structure(list(t = c(10, 10, 10, 10), f1j = c(0.25, 0, 0, 0.25
), f2j = c(0.25, 0, 0, 0.25), f3j = c(0.25, 0, 0, 0.25), f4j = c(0.25, 0, 0.25, 0.25), f5j = c(0, 0.25, 0, 0.25)), .Names = c("t", "f1j", "f2j", "f3j", "f4j", "f5j"), row.names = c(NA,-4L), class = "data.frame")
tolerance <- 0
Tau.Fij.opt.mat.1st <- ifelse(vardata > tolerance ,vardata,0)
Pos.list <- Tau.Fij.opt.mat.1st[Tau.Fij.opt.mat.1st>0] #get all values>0
Pos.loc <- which(Tau.Fij.opt.mat.1st > 0, arr.ind = TRUE) #get locations>0
Zero.list <- Tau.Fij.opt.mat.1st[Tau.Fij.opt.mat.1st==0]
Zero.loc <- which(Tau.Fij.opt.mat.1st == 0, arr.ind = TRUE)
my.data.var.1st <- Pos.list # variables to be evaluated
Error.func.1st <- function(my.data.var.1st,Pos.loc,Zero.loc,Zero.list) #my.data.var.1st,Pos.loc,Zero.loc,Zero.list
{
#First convert vector(my.data.var) to MATRIX aand send it to calculate new MATRIX
my.data.var.mat.1st <- matrix(,nrow = 4,ncol = 6,byrow = TRUE)
my.data.var.mat.1st[Pos.loc] <- my.data.var.1st
if(length(Zero.loc)>0)
{
my.data.var.mat.1st[Zero.loc] <- Zero.list
}
Error <- my.data.var.mat.1st
}
AA <- Error.func.1st(my.data.var.1st,Pos.loc,Zero.loc,Zero.list)
I found the error in my code. 我在代码中发现错误。 The input matrix from C# had to be transposed before being used.
来自C#的输入矩阵必须在使用前进行转置。 Hence, the error about "Subscript out of bounds".
因此,关于“下标超出范围”的错误。 Setting this as closed.
将其设置为关闭。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.