Re: [R] how to get the miminum value in the list

2011-06-20 Thread Petr PIKAL
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]]
> [[2]][[1]]
> [1] 1
> 
> [[2]][[2]]
> [1] 5
> 
> unlist(lapply(seq_len(length(y)), function(i) lapply(y[[i]], min)))
> [1] 1 2 1 5

Or you can use rapply

rapply(y, min)
[1] 1 2 1 5

Regards

Petr

> 
> HTH,
> Dennis
> 
> On Sun, Jun 19, 2011 at 8:25 AM, jiliguala  wrote:
> >
> > 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-tp3609013p3609433.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to get the miminum value in the list

2011-06-19 Thread Dennis Murphy
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)))
[1] 1 2 1 5

HTH,
Dennis

On Sun, Jun 19, 2011 at 8:25 AM, jiliguala  wrote:
>
> 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-tp3609013p3609433.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to get the miminum value in the list

2011-06-19 Thread jiliguala

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-tp3609013p3609433.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to get the miminum value in the list

2011-06-19 Thread Daniel Malter
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.

x<-list(c(1,5),c(2,3,4))
lapply(x,min)
min(unlist(x))

HTH,
Daniel


jiliguala wrote:
> 
> hi, R users 
> 
> here i have one problem, if i wanna get the minimum value in the normal
> data, i can do this,
> 
> ## which(data1==min(data1)).
> 
> but if i want get the minimum value of a list which has two variables
> ##list1[[j]][[i]]##,
> i tried the codes like this, but it did not work.
> 
> ##  which(list1==min(list1)).
> 
> thanks for helping
> 

--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-get-the-miminum-value-in-the-list-tp3609013p3609325.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.