【发布时间】:2018-04-21 12:21:59
【问题描述】:
我如何才能确定类列表中的哪个元素具有最小属性 X,以及列表中的其他属性 X?
让我以更具体的方式告诉你我的意思。
# class setup
setClass(
"Stackoverflow",
slots = list(
x = "numeric",
y = "numeric"
)
)
#generate the list of classes
l = list()
for (i in 1:10)
{
l[[i]] <- myLove4U <- new("Stackoverflow",
x = runif(1, min=0, max=100),
t = runif(1, min=0, max=100)
)
}
#find which is the element that has the smallest x
# ??
问号是我想知道如何实现的代码。
我试过了,没有什么好的结果,这样:min(l[]@x)
这会让我知道其中的最小值,然后搜索具有它的索引。
因为我什至找不到最小值,所以我完全迷失了。你能帮我找到解决办法吗?
【问题讨论】: