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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:50:10+00:00 2026-05-31T04:50:10+00:00

I clearly still don’t understand plyr syntax, as illustrated below. Can someone help me

  • 0

I clearly still don’t understand plyr syntax, as illustrated below. Can someone help me see what I’m missing?

The following code works fine, as expected:

# make a data frame to use dlply on 
f <- as.factor(c(rep("a", 3), rep("b", 3)))
y <- rnorm(6)
df <- data.frame(f=f, y=y)

# split the data frame by the factor and perform t-tests
l <- dlply(df, .(f), function(d) t.test(y, mu=0))

However, the following causes an error

l_bad <- dlply(df, .(f), t.test, .mu=0)
Error in if (stderr < 10 * .Machine$double.eps * abs(mx)) stop("data are essentially constant") : missing value where TRUE/FALSE needed

Which looks a bit as if R is trying to perform a t.test on the factor. Why would that be? Many thanks.

  • 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-31T04:50:11+00:00Added an answer on May 31, 2026 at 4:50 am

    dlply splits df into several data frames. That means that whatever function you hand off to dply must expect a data frame as input. t.test expects a vector as it’s first argument.

    Your anonymous function in dlply declares d as its only argument. But then in your call to t.test you pass only y. R doesn’t automatically know to look in the data frame d for y. So instead it’s probably finding the y that you defined in the global environment.

    Simply changing that to t.test(d$y,mu = 0) in your first example should make it work.

    The second example will only work if the function to be applied is expecting a data frame as input. (i.e. see summarise or transform.)

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

Sidebar

Related Questions

I cannot figure out why it's still not recognizing jQuery syntax when I clearly
Can someone explain clearly why this implementation (from SO 3965054) of min_of_list works in
I clearly do not understand git at all. This is what I'm getting: git
How can we clearly differ architectural term abstraction from a software component, can abstraction
How can you clearly illustrate multiple threads of execution in a sequence diagram or
I never clearly understood what an ABI is. Please don't point me to a
I don't know C well at all, and I'm trying to edit someone's code,
I'd already ask about this, but still don't have an answer. I think the
Newbie technical difficulty here. Hope I can explain this clearly. in My DB, I
I'm having a little problem and I don't see why, it's easy to go

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.