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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:16:17+00:00 2026-06-17T20:16:17+00:00

I have data from some games, where, in every game, a variable number of

  • 0

I have data from some games, where, in every game, a variable number of players scored goals. I now want to distribute the number of goals in every single game, to the players that participated in that game. And I finally like to get the sum of goals every player has scored in all games combined.

Example:

Game 1: Players A + B + C; Goals: 3; so everyone gets a score of 1
Game 2: Players A + B + D + E; Goals: 8; everyone gets a score of 2
Game 3: Players B + C; Goals: 4; everyone gets a score of 2

Results: (this is what if want to create)

A: 3
B: 5
C: 3
D: 2
E: 2

This data is available in a CSV, where the variable players per game are put into a single column separated by a pipe (|):

Players;Goals
A|B|C;3
A|B|D|E;8
B|C;4
E;3

I can read this into a data.frame:

data <- read.csv("demo.csv", header=TRUE, sep=";")

and also separate the players info from the Players column in the data.frame:

lapply(data$Players, function(x) strsplit(as.character(x), "|", fixed=TRUE))

How do I distribute the scores from the Goals column to these players?

  • 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-17T20:16:18+00:00Added an answer on June 17, 2026 at 8:16 pm

    Here’s something using base functions and *apply:

    #input data (from clipboard)
    data <- read.table(header=TRUE,sep=";",file='clipboard')
    players <- strsplit(as.character(data$Players),"|",fixed=TRUE)
    #number of players in a game
    data$n.player <- sapply(players,length)
    #unique list of players
    uni.players <- unique(unlist(players))
    
    goals.per.player <- sapply(uni.players,function(x) {
      #identifies which games (rows of data) each player was in
      games.played <- which(sapply(players, function(y) x %in% y))
      #sums the games played
      sum((data$Goals/data$n.player)[games.played])
    })
    #A B C D E 
    #3 5 3 2 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some game data in my GameStateSingleton , which I don't want to
I have some tables that contain data about players and the games they have
I need to get some data from a column. For example I have data
I have some data from log files and would like to group entries by
I have some data from a external party which is encrypted according to them
I have some data from JQGrid that should be exported to excel. So, we
I have data from two different sources that I need to combine. Some data
I have been tasked to read in some data from some weird old system.
I have a class that contains data from some model. This class has metadata
I have fetched some data from a SQL database into a datagridview, but after

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.