Filter(is.atomic, something)
returns atomic vectors.
1. Weather -example here
> Filter(is.atomic, study)
$region
[1] "Hamburg" "Bremen"
2. mosaic-plot-as-tree-plot -example here
> Map(function(x) Filter(is.atomic, x), ls())
$g
[1] "g"
$lookup
[1] "lookup"
$req.data
[1] "req.data"
$tmp
[1] "tmp"
$tmp1
[1] "tmp1"
Look their positions can be arbitrary, I may have faintest clue of their data-structure so cannot use var$some$...$vector. I feel the need of ?Position. Use your imagination, the examples are not exclusive. How can I access their atomic vectors?
To flatten a list so you can access the atomic vectors, you can use following function:
This function maintains names of the elements. Usage, using the list x from Vincent’s answer :
then:
To recursively do an action on all atomic elements in a list, use
rapply()(which is what Vincent handcoded basically).See also
?rapplyPS : Your code
Map(function(x) Filter(is.atomic, x), ls())doesn’t make sense.ls()returns a character vector, so every element of that character vector will be returned as part of the list. This doesn’t tell you anything at all.Next to that,
Filter()doesn’t do what you believe it does. Taking the example listx, from the answer of Vincent, accessing only the atomic parts of it is pretty easy.Filter()only returns the second element. That’s the only atomic element.Filter(is.atomic, x)is 100% equivalent to: