listCrawler {crank} | R Documentation |
Descend a possibly nested list, seeking the element that has the extreme value of a function.
listCrawler(x,FUN=NULL,maxval=TRUE, retval=list(indx=vector("numeric",0),element=NULL,value=NA))
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.
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
# a simple example using the square root function testlist<-list(list(9,16),list(25,list(36,49))) listCrawler(testlist,sqrt)