[R] max number from a list of numbers

(Ted Harding) Ted.Harding at manchester.ac.uk
Thu May 20 21:43:11 CEST 2010


On 20-May-10 19:29:31, Jonathan 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

Hi Jonathan,
Just "unlist" it:

  husk <- list(c(2,5),c(2,17),2,17)
  husk
  # [[1]]
  #  [1]   2  5
  # [[2]]
  #  [1]   2 17
  # [[3]]
  #  [1]   2 
  # [[4]]
  #  [1]  17

  max(unlist(husk))
  # [1] 17

Hoping this helps,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 20-May-10                                       Time: 20:43:07
------------------------------ XFMail ------------------------------



More information about the R-help mailing list