我正在尝试避免循环,但不确定如何执行此操作:
假设我有以下内容:
theList <- list()
theList[[1]] <- list(foo = "1", bar = "10")
theList[[2]] <- list(bar = "10", foo = "4")
theList[[3]] <- list(foo = "-1", bar = "10")
如何调用函数以便返回foo的最小值?
minValue(theList$foo)
或类似的东西......会返回-1。
答案 0 :(得分:2)
你可以尝试
v1 <- unlist(theList)
min(as.numeric(v1[names(v1)=='foo']))
#[1] -1