Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7030241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:38:40+00:00 2026-05-28T00:38:40+00:00

Filter(is.atomic, something) returns atomic vectors. 1. Weather -example here > Filter(is.atomic, study) $region [1]

  • 0
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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:38:41+00:00Added an answer on May 28, 2026 at 12:38 am

    To flatten a list so you can access the atomic vectors, you can use following function:

    flatten.list <- function(x){
      y <- list()
      while(is.list(x)){
        id <- sapply(x,is.atomic)
        y <- c(y,x[id])
        x <- unlist(x[!id],recursive=FALSE)
      }
      y
    }
    

    This function maintains names of the elements. Usage, using the list x from Vincent’s answer :

    x <- list(
       list(1:3, 4:6),
       7:8,
       list( list( list(9:11, 12:15), 16:20 ), 21:24 )
    )
    

    then:

    > flatten.list(x)
    [[1]]
    [1] 7 8
    
    [[2]]
    [1] 1 2 3
    
    [[3]]
    [1] 4 5 6
    
    [[4]]
    [1] 21 22 23 24
    
    ...
    

    To recursively do an action on all atomic elements in a list, use rapply() (which is what Vincent handcoded basically).

    > rapply(x,sum)
    [1]  6 15 15 30 54 90 90
    
    > rapply(x,sum,how='list')
    [[1]]
    [[1]][[1]]
    [1] 6
    
    [[1]][[2]]
    [1] 15
    
    
    [[2]]
    [1] 15
    
    ...
    

    See also ?rapply

    PS : 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 list x, 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:

    ind <- sapply(x, is.atomic)
    x[ind]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is Berkley Packet Filter supported on Windows or is there something comparable which I
How filter the files by extensions (in the screen), like this example thanks, celso.
I have to filter GridView data based on the Tab Panel selected, Here is
Silverlight filter/class for cloud generation? Some HLSL or just C# class for generating clouds?
I need to filter out anchor tags in a string. For instance, Check out
I would like to filter an array of items by using the map() function.
I currently filter some message from my inbox with these steps: select inbox pick
How can you cascade filter the attributes of more dimensions in a SSAS cube,
I have a filter attribute that I'd like to be applied to every action
I want to filter the selectable dates on a datepicker. I basically need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.