Hi
r-help-boun...@r-project.org napsal dne 19.06.2011 20:45:04:
>
> Hi:
>
> It's just an extra step:
>
> y <- list(list(c(1,5),c(2,3,4)), list(c(1, 3, 4), c(5, 7)))
> lapply(seq_len(length(y)), function(i) lapply(y[[i]], min))
> [[1]]
> [[1]][[1]]
> [1] 1
>
> [[1]][[2]]
> [1] 2
>
> [[2]]
> [
Hi:
It's just an extra step:
y <- list(list(c(1,5),c(2,3,4)), list(c(1, 3, 4), c(5, 7)))
lapply(seq_len(length(y)), function(i) lapply(y[[i]], min))
[[1]]
[[1]][[1]]
[1] 1
[[1]][[2]]
[1] 2
[[2]]
[[2]][[1]]
[1] 1
[[2]][[2]]
[1] 5
unlist(lapply(seq_len(length(y)), function(i) lapply(y[[i]], min
but in my case, the list is a two-variable list, list[[j]][[i]]
when i use
lapply(list, min)
it appears
"""Error in FUN(X[[1L]], ...) : invalid 'type' (list) of argument"""
thanks
--
View this message in context:
http://r.789695.n4.nabble.com/how-to-get-the-miminum-value-in-the-list-tp360
Hi, that depends on whether you want to get the minimum within each list
element or the global minimum across all list elements. The first is
achieved by using lapply(). The second can be achieved by unlisting the list
(which assumes that all list elements are numeric) and looking for its
minimum.
4 matches
Mail list logo