[R] max number from a list of numbers
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@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] max number from a list of numbers
I think you want unlist with recursive = TRUE, see ?unlist. Bryan * Bryan Hanson Acting Chair Professor of Chemistry Biochemistry DePauw University, Greencastle IN USA On 5/20/10 3:29 PM, Jonathan jonsle...@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@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] max number from a list of numbers
You have a list that you want to treat as a vector, so ?unlist it. 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 [[alternative HTML version deleted]] __ 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] max number from a list of numbers
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 jonsle...@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@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/ __ 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] max number from a list of numbers
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.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 20-May-10 Time: 20:43:07 -- XFMail -- __ 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.