[R] max number from a list of numbers

Joshua Wiley jwiley.psych at gmail.com
Thu May 20 21:38:22 CEST 2010


Hello Jonathan,

Look at ?sapply  Does something like this do what you want?

max(sapply(yourlist, max))


Josh

On Thu, May 20, 2010 at 12:29 PM, Jonathan <jonsleepy at gmail.com> wrote:
> Hi all,
>   I'm hoping this question has a simple answer, but I can't find it through
> searching or trying commands.
>
> I have a list of numeric vectors called 'husk'.  I'd just like to treat the
> set of all numbers from all vectors in the list as if it were one large
> vector, because I'd like to extract information, such as what is the max
> entry from all the numbers.
>
>> husk
> [[1]]
> [1] 2 5
>
> [[2]]
> [1]  2 17
>
> [[3]]
> [1] 2
>
> [[4]]
> [1] 17
>
>> max(husk)
> Error in max(husk) : invalid 'type' (list) of argument
>
>> max(husk[])
> Error in max(husk[]) : invalid 'type' (list) of argument
>
>> max(husk[[]])
> Error in husk[[]] : invalid subscript type 'symbol'
>
>> max(husk[[1:length(husk)]])
> Error in husk[[1:length(husk)]] : recursive indexing failed at level 2
>
>> max(husk[1:length(husk)])
> Error in max(husk[1:length(husk)]) : invalid 'type' (list) of argument
>
> Any ideas would be appreciated!
>
> Best,
> Jonathan
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>



-- 
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/



More information about the R-help mailing list