带着一个让我困惑的问题又回来了。这有点类似于这篇文章:How can I see multiple variable's outlier in one boxplot using R?,但我试图迭代的不仅仅是一列。
我希望我的代码具有一定的可重复性:
library(extremevalues)
data(cars)
result<-list()
nFits<-list()
methodz<-c("I","II")
dists<-c("exponential","normal","lognormal","pareto","weibull")
for (i in seq_along(methodz)){
for(j in seq_along(dists)){
for(k in 1:ncol(cars)){
nFits[[i]] <-getOutliers(cars[k],
method=methodz[i],distribution=dists[j])$nFit
result<-nFits
}
}
}
我的目标是检查我的每一个连续结果的极端值,以确定最合适的行动方案。对于每个变量,我希望为两种方法类型和所有5个发行版运行getOutliers函数,并将nFit、yMin和yMax保存到一个数据框中以供查看。nFits、yMin和yMax都是getOutliers的输出。
我知道我没有正确地下标每个list对象,因为我一直收到不正确的下标数量错误。如果您能提供任何建议,我们将不胜感激!
发布于 2018-07-01 00:28:40
一种方法是创建一个嵌套的list
,然后将getOutliers
的输出分配给它
methodz <- c("I","II")
dists <- c("exponential","normal","lognormal","pareto","weibull")
nFits <- replicate(length(methodz), vector("list", length(dists)),
simplify = FALSE)
for (i in seq_along(methodz)){
for(j in seq_along(dists)){
for(k in seq_along(cars)){
nFits[[i]][[j]][k] <- getOutliers(cars[[k]],
method=methodz[i],distribution=dists[j])$nFit
}
}
}
https://stackoverflow.com/questions/51111341
复制相似问题