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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:56:14+00:00 2026-06-10T16:56:14+00:00

I met a wired problem while sapply subset to a list of dataframe inside

  • 0

I met a wired problem while sapply subset to a list of dataframe inside a function that R saying “Error in eval(expr, envir, enclos) : object ‘thresh’ not found“. I wonder why this would happen.

test<-list()
test[[1]]<-as.data.frame(matrix(rnorm(50*5,10,100),50,5))
test[[2]]<-as.data.frame(matrix(rnorm(50*5,10,100),50,5))


findmax<-function(test,thresh){
  print(thresh)
  max(unlist(sapply(test,subset,V1>thresh,select=c("V1"))))
}

findmax(test,thresh=10)
  • 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-10T16:56:16+00:00Added an answer on June 10, 2026 at 4:56 pm

    Do heed the Warning in ?subset:

    Warning:
    
         This is a convenience function intended for use interactively.
         For programming it is better to use the standard subsetting
         functions like ‘[’, and in particular the non-standard evaluation
         of argument ‘subset’ can have unanticipated consequences.
    

    subset has some strange evaluation rules as to where it looks for objects and variables therein, which depend upon calling environments etc. These work fine when called by the user interactively at the top level, but often fail when wrapped inside functions as you have found.

    Here is one way to rewrite the function using standard subsetting:

    findmax <- function(test, thresh, want) {
        foo <- function(x, thresh, want) {
           take <- x[, want] > thresh
           x[take, want]
        }
        max(unlist(sapply(test, foo, thresh = thresh, want = want)))
    }
    findmax(test, thresh = 10, want = "V1")
    

    which for your test data gives:

    R> findmax(test, thresh = 10, want = "V1")
    [1] 230.9756
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I met a problem when Call to a member function combinestring() on a non-object.
I met a problem with sum function: the data have a datetime column and
I met some compilation error but do not know what the problem is. The
I met this message of error while trying to save an image which has
I met the problem that I want only show the sub directories but my
I met a wired problem for a web page in IE7/8. The page configured
I met a problem like this. class A have a list of class B.
I met a runtime error double free or corruption in my C++ program that
I met a problem while using python(2.6) cgi to show a mime data in
I met strange problem. I have never work with Devise gem before. So, i

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.