0
當我通過R.net(從C#代碼輸入數據)運行R腳本時,出現「下標越界」錯誤。奇怪的是,如果我通過excel提供相同的輸入數據時運行Rscript,它運行良好!任何想法爲什麼會發生?我從C#代碼發送「vardata」。R.net在評估過程中出現錯誤 - 「下標越界」
*
***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)