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

  • Home
  • SEARCH
  • 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 7701277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:56:45+00:00 2026-05-31T22:56:45+00:00

I have a three part question based on a dataframe (df is example rows)

  • 0

I have a three part question based on a dataframe (df is example rows) of goals scored by soccer players in a season

 Player           Season  Goals
 Teddy Sheringham 1992/3   22
 Les Ferdinand    1992/3   20
 Dean Holdsworth  1992/3   19
 Andy Cole        1993/4   34
 Alan Shearer     1993/4   31
 Chris Sutton     1993/4   25

If I want to obtain the top scorer each year I can use

ddply(df, "Season", summarise, maxGoals = max(Goals),
      Player=Player[which.max(Goals)])

Questions:

1) It does not apply in this case but does this suffice if there are joint top scorers

2) I am also interested in the runner up for each season being extracted. I have played around with sorting on Goals descending and index 2 but have not found solution

3) Also how would I obtain a count value for each year based on number of Goals scored e.g Goals>20 should give 1 for 1992/3 and 3 for 1993/4 on the above data

  • 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-31T22:56:46+00:00Added an answer on May 31, 2026 at 10:56 pm

    If there are multiple best players, that expression will report only one of them (specifically, the first in the dataframe in that year).

    For q2:

    d = ddply(df, "Season", summarise, SecondPlayer=Player[order(Goals)[length(Goals)-1]])
    

    For q3:

    d = ddply(df, "Season", summarise, Count=sum(Goals > 20))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two part question. First, I'm writing a web-scraper based on the
I have three divs stacked on each other but offset so that a part
Based in part on the advice in this response to a question on SO
hi i have created a question answer based app, the question's used to be
As part of an Excel based scheduler that I have created, I am using
I am writing this question in part based on a related question on helper-scripts
Question 1: I have some XML-based layouts which work fine on phones. But when
I have a tree of active record objects, something like: class Part < ActiveRecord::Base
Is there someway to have a part of the page that renders like a
Have three classes User, Group and Field. Many to many relationship on User /

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.