【发布时间】:2015-08-25 08:45:12
【问题描述】:
我想将 1000 个随机变量乘以一个矩阵,从而得到 1000 个不同的结果矩阵。
我正在运行以下代码:
Threshold <- runif(1000,min=0,max=1) #Generating 1000 random variables so that we can see 1000 multiple results of Burstscore
Burstscore <- matrix(data=0,nrow=nrow(Fm2),ncol=ncol(Fpre2))
#Calculating the final burst score
for (i in 1:nrow(Fm2)){
for (j in 1:ncol(Fpre)){ #Dimentions of all the matrices (Fpre,Fm,Growth,TD,Burstscore) are 432,24
{
Burstscore[i,j]= ((as.numeric(Threshold))*(as.numeric(Growth[i,j]))) + ((1-(as.numeric(Threshold)))*(as.numeric(TD[i,j])))
}
}
}
我收到以下错误 -
'Error in Burstscore[i, j] = ((as.numeric(Threshold)) * (as.numeric(Growth[i, :
number of items to replace is not a multiple of replacement length'
【问题讨论】:
-
不可重现,我们无权访问
Fm2对象。 -
@Pascal 我们愿意。方程中的其他两个矩阵直接取决于 Fm 和 Fpre 变量。这些变量早先在代码中使用并且具有相同的维度。
-
我们 = 潜在的帮助者。
-
@Pascal 哦,我明白了。对不起。但这里的主要问题是我如何运行这个循环,以便它返回 1000 个结果矩阵。
-
是的,我明白了。但是当问一个关于 SO 的问题时,你被要求提供一个最小的可重现的例子。这有助于了解上下文、您使用的数据格式以及您想要获得的数据。