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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:53:12+00:00 2026-06-06T08:53:12+00:00

so this is a simple question, and it’s unclear to me what’s going wrong

  • 0

so this is a simple question, and it’s unclear to me what’s going wrong with this plyr call.

library(plyr)

some silly data with a binomial outcome (y1) and two four-level classifying factors(x1 and x2):

df <- data.frame(x1 = sample(letters[1:4], 4000,T),
                 x2 = sample(LETTERS[5:8], 4000,T),
                 y1 = rbinom(n=4000,1,.5))

I want a table with the row proportions of each outcome–and i thought the following would work

foo <- ddply(df, .(x1,x2), function(i) prop.table(table(i$y1),1))

but instead it gives me:

head(foo)

  x1 x2 0 1
1  a  E 1 1
2  a  F 1 1
3  a  G 1 1
4  a  H 1 1
5  b  E 1 1
6  b  F 1 1

which is clearly not what i’m looking for. What’s my omission?

  • 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-06T08:53:13+00:00Added an answer on June 6, 2026 at 8:53 am

    try

    foo<-ddply(df, .(x1,x2), function(i) prop.table(table(i$y1)))
    
    > head(foo)
      x1 x2         0         1
    1  a  E 0.5365854 0.4634146
    2  a  F 0.4936170 0.5063830
    3  a  G 0.5176471 0.4823529
    4  a  H 0.4568966 0.5431034
    5  b  E 0.4780702 0.5219298
    6  b  F 0.5617530 0.4382470
    

    not sure if thats what you want

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

Sidebar

Related Questions

Apologies about this simple question. Still struggling with some of the memory concepts here.
I have this simple question. Previously, when I wanted to call a controller method
Shamed by this simple question. For some reason, I want to put all asp.net
Sorry for this simple question, but I can't solve it... There is an example:
i have this simple question please. I have this part of code which sets
A simple answer to this super simple question would be great! Here is the
I searched and searched for an answer for this seemingly simple question in Commerce
This is a simple question really (but I couldn't seem to find the answer
This is a simple question I think. I am trying to search for the
This is a simple question really. I've been using the new type of constructors

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.