我得到"下标超出界限"我通过R.net运行R脚本时出错(从C#代码输入数据)。奇怪的是,如果我在excel提供相同的输入数据时运行Rscript,它运行正常!关于它为什么会发生的任何想法?我发送" vardata"来自C#代码。
*
***Error in my.data.var.mat.1st[Pos.loc] <- my.data.var.1st :
subscript out of bounds***
*
以下是代码和相关信息。
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)
答案 0 :(得分:0)
我在代码中发现了错误。来自C#的输入矩阵必须在使用前进行转置。因此,关于&#34;下标超出界限的错误&#34;。将其设置为已关闭。