【发布时间】:2016-04-18 21:28:04
【问题描述】:
是否可以在R中存储变量..
我必须计算 10*324 fitdist,这个函数的每个输出都必须存储在上述大小的矩阵中?这在 R 中可能吗?
如果是这样,那我完全迷路了怎么办?
所以我试着创建一个简单的例子
norm_dist <- as.data.frame(matrix(nrow=3,ncol=3))
data(iris)
for(i in 1:3)
{
for(j in 1:3)
{
print(i)
print(j)
if(j==1)
{
element = fitdist(data =iris$Petal.Width[1:50*i], distr = "norm")
norm_dist[i,j] = element
}
if(j==2)
{
element = fitdist(data =iris$Petal.Length[1:50*i], distr = "norm")
norm_dist[i,j] = element
}
if(j==3)
{
element = fitdist(data =iris$Sepal.Length[1:50*i], distr = "norm")
norm_dist[i,j] = element
}
}
}
但是我收到了这个错误
Error in `[<-.data.frame`(`*tmp*`, i, j, value = list(estimate = c(0.867771222640304, :
replacement element 4 is a matrix with 2 rows, needs 1
我不确定我是否理解它的意思......
【问题讨论】:
-
创建一个远小于 8000*324 的示例,并将其包含在您的问题中。
-
我尝试创建一个简单的例子
-
data(Iris) 似乎已被添加,谢谢@J.Down :) 现在看来可以重现了..
-
欢迎来到 SO!,马修的意思是 how to post a great reproducible example
-
现在不是这样吗?
标签: r for-loop matrix fitdistrplus