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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:51:53+00:00 2026-06-13T00:51:53+00:00

x Team Date Score A 1-1-2012 80 A 1-2-2012 90 A 1-3-2012 50 A

  • 0

x

Team Date       Score
A    1-1-2012   80
A    1-2-2012   90
A    1-3-2012   50
A    1-4-2012   40   
B    1-1-2012   100
B    1-2-2012   60
B    1-3-2012   30
B    1-4-2012   70
etc

I need to and can turn this data frame to wide data frame one row for each team with all the observations and dates as the heading:

xx

Team 1-1-2012 1-2-2012  1-3-2012 1-4-2012
A    80       90        50        40
B    100     60         30        70  

I need to calculate the mean and sd for each row, which I can do:

xx

Team 1-1-2012 1-2-2012  1-3-2012 1-4-2012  mean   sd
A    80       90        50        40       75    20
B    100     60         30        70       55    10 

Considering I have thousands of row in data frame xx. I would like to do calculation on each cell as this:

if abs(xx-Mean) > 3*SD, create a counter column name and increment the value. The idea is that compare each observation against the mean and sd, if each observation for a given team matches this – abs(xx-Mean) > 3*SD, increment the counter. After checking each cell, I would like to look at each counter for each team and get the top ten high team that has the highest counter value. Basically I am trying to detect the most outliers. Once I get the top 10 team names, I would like to graph their time series data on data frame x.

I hope I am not making this more complicated than it should be. Not sure, R already has function to do calculations on each cell. Any ideas how to accomplish this is appreciated?

  • 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-13T00:51:54+00:00Added an answer on June 13, 2026 at 12:51 am

    A long-format, data.table approach

    DT <- read.table( 'clipboard', header = T)
    library(data.table)
    DT <- as.data.table(DT)
    DT[, mean.score := mean(Score), by = Team]
    ##    Team     Date Score mean.score
    ## 1:    A 1-1-2012    80         65
    ## 2:    A 1-2-2012    90         65
    ## 3:    A 1-3-2012    50         65
    ## 4:    A 1-4-2012    40         65
    ## 5:    B 1-1-2012   100         65
    ## 6:    B 1-2-2012    60         65
    ## 7:    B 1-3-2012    30         65
    ## 8:    B 1-4-2012    70         65
    DT[, sd.score := sd(Score), by = Team]
    ##    Team     Date Score mean.score sd.score
    ## 1:    A 1-1-2012    80         65 23.80476
    ## 2:    A 1-2-2012    90         65 23.80476
    ## 3:    A 1-3-2012    50         65 23.80476
    ## 4:    A 1-4-2012    40         65 23.80476
    ## 5:    B 1-1-2012   100         65 28.86751
    ## 6:    B 1-2-2012    60         65 28.86751
    ## 7:    B 1-3-2012    30         65 28.86751
    ## 8:    B 1-4-2012    70         65 28.86751
    DT[, outlier := abs(Score-mean.score) > 3 * sd.score, by = Team]
    ##    Team     Date Score mean.score sd.score outlier
    ## 1:    A 1-1-2012    80         65 23.80476   FALSE
    ## 2:    A 1-2-2012    90         65 23.80476   FALSE
    ## 3:    A 1-3-2012    50         65 23.80476   FALSE
    ## 4:    A 1-4-2012    40         65 23.80476   FALSE
    ## 5:    B 1-1-2012   100         65 28.86751   FALSE
    ## 6:    B 1-2-2012    60         65 28.86751   FALSE
    ## 7:    B 1-3-2012    30         65 28.86751   FALSE
    ## 8:    B 1-4-2012    70         65 28.86751   FALSE
    

    Or, in a single step

    DT[, outlier := abs(Score-mean(Score)) > 3 *  sd(Score), by = Team]
    

    To add the number of outliers (sum on a logical variable will coerce to 0,1)

    DT[, sum.outlier := sum(outlier), by = Team]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My original data frame is this: x Team Date variable value A 2012-07-01 Score
I have a data frame like this Date Team Score 1/1/2010 A 10 1/1/2010
My data is this: ID,SCORE_DATE,TYPE,SCORE,RAW_SCORE,RANK A1234,2012-09-05 23:59:59,FOOTBALL_TEAM_MIDDLE_AND_OLD_1234,10,0.123,1 A5678,2012-09-05 23:59:59,FOOTBALL_TEAM_MIDDLE_AND_OLD_1234,20,0.456,2 CTL FILE: load data infile
So I have a sample data set like this in csv:- name team date
Can anyone see an obvious error in this query? function getFixtureDetails($league, $date, $status) {
I would like to order by date and then team in a MySQL query.
I want to get the date object text content and Team 1. But Team
Here is a query string that I use to plug into a form: team,site,week,day,date,o:team,line,points,o:points@season=2011
Our team crawls websites to keep our info up to date. I was running
I recently came accross a conflict within my team where in a row was

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.