Description Usage Arguments Details Value Author(s) See Also Examples
Descend a possibly nested list, seeking the element that has the extreme value of a function.
1 2 |
x |
The object that will be the first argument of FUN, or a possibly nested list of such objects. |
FUN |
A function that can accept x as its first argument. |
maxval |
Whether to look for maximal (TRUE) or minimal (FALSE) values of the function FUN. |
retval |
The list that is eventually returned. |
listCrawler descends the list structure of x applying FUN to any non-list elements it encounters. If the value of FUN is larger or smaller than the current extremum (depending upon the value of maxval), the new value becomes the current extremum. The default value of FUN just takes the value of the elements.
A list containing:
indx |
the indices of the element producing the extreme value of FUN. |
element |
The element that produced the extremum. |
value |
The extreme value of FUN. |
Jim Lemon
list, listBuilder
1 2 3 4 5 6 | # a simple example using the square root function
testlist<-list(list(9,16),list(25,list(36,49)))
# first get the default maximum
listCrawler(testlist,sqrt)
# then the minimum
listCrawler(testlist,sqrt,maxval=FALSE)
|
$indx
[1] 2 2 2
$element
[1] 49
$value
[1] 7
$indx
[1] 1 1
$element
[1] 9
$value
[1] 3
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.