-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
index/position to find result from list.search in original list #104
Comments
What is the expected result you're trying to get, @timelyportfolio? |
Well, some kind of path or pointer to the item where the search returns
However, I do not know of a way in |
|
Ok that was my impression. I just wanted to make I sure I did not miss it. I have a local function that sort of works but needs some iteration. Thanks for confirming. |
I implement a simple list.query <- function(x,
filter = function(x, i, name) TRUE,
map = function(x, i, name) x,
parent.i = integer(), parent.names = character(),
results = new.env(parent = emptyenv()),
convert = TRUE) {
if (is.list(x)) {
.mapply(function(x, i, name) {
i <- c(parent.i, i)
name <- c(parent.names, name)
if (filter(x, i, name)) {
results[[as.character(length(results) + 1L)]] <- map(x, i, name)
}
list.query(x, filter, map,
parent.i = i, parent.names = name, results = results, convert = FALSE)
}, list(x, seq_along(x), if (is.null(names <- names(x))) "" else names), NULL)
}
if (convert) unname(as.list.environment(results))
} Each time Some query might be possible to help building the |
Using this function, the dh <- as.dendrogram(hclust(dist(USArrests), "ave"))
list.query(dh, filter = function(x, i, name) {
label <- attr(x, "label")
!is.null(label) && label == "Alabama"
}, map = function(x, i, name) {
list(x = x, i = i)
})
The result set include both the object and its indexed position. |
Is there a mechanism to retrieve the index/position from a
list.search
result? As an example, let's use a good olddendrogram
. Most of the important meta information for adendrogram
is stored inattributes
.If we wanted to find the node labelled Alabama, we could do something like this.
Now, is there any way to take the result which I called
dl_search
to get this item in the original list? I found this, but I was hoping for something more elegant. With the changes introduced in befdb80, I think it really becomes impossible.The text was updated successfully, but these errors were encountered: