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 9223375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:03:49+00:00 2026-06-18T04:03:49+00:00

I have a named list of data.frame objects ( training_data ). Each data.frame object

  • 0

I have a named list of data.frame objects (training_data). Each data.frame object will be tested based on a “x” column and if the test is passed, the name of that data.frame object is supposed to be returned.

In the case below, “a” and “b” are supposed to be returned:

df <- data.frame(x=1:10, y=1:10)
df1 <- data.frame(x=11:20, y=11:20)
training_data <- list(df, df, df1, df1)
names(training_data) <- c("a", "b", "c", "d")

pos <- lapply(training_data, function(data) {
                                 if(data$x==1)
                                    ["return the name of the data.frame object in hand"]
                              })

My question is how exactly one can determine the name of the object currently being processed within any iteration of lapply and how to return that name so that it goes to “pos” list.

Regards

  • 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-06-18T04:03:50+00:00Added an answer on June 18, 2026 at 4:03 am

    No need to use lapply here, you can access your list for example :

    training_data[['pos']] 
    

    This will give you acess to the data.frame named ‘pos’ or posxx…

    EDIT after OP clarification

    I use lapply in the names of the list , I and I use the same mode of acces above to the main list

    pos <- lapply(names(training_data), function(data) {
      if(training_data[[data]]$x==1)        ## here your condition is not correct
        data
    
    })
    
      [[1]]
    [1] "a"
    
    [[2]]
    [1] "b"
    
    [[3]]
    NULL
    
    [[4]]
    NULL
    

    You can remove the NULL elements using something like

    unlist(pos)
    [1] "a" "b"
    

    but I think you will get better output here if you use sapply, which returns named list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this nested data frame test <- structure(list(id = c(13, 27), seq =
I have a list of xts objects. I'd like to get a data.frame with
I have a list of data.frame objects which i would like to row append
So let's assume I have a class named ABC that will have a list
I have the following test data: structure(list(r = c(5.44702625911984, 6.3431860464319, 2.89023592667928, 6.66260769449341, 7.5521021076857, 5.50645078944005,
I have this data frame: dput(df2) structure(list(Receiver = structure(c(4L, 3L, 2L, 1L), .Label =
I have a similar data frame as follows: mapDF <- structure(list(var = c(11L, 3L,
I have a data.frame like this: (t=structure(list(count = c(NA, 2, NA, NA, NA, 8,
So I have a bunch of data frames in a list object. Frames are
So I have a bunch of data frames in a list object. Frames are

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.