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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:58:29+00:00 2026-06-18T00:58:29+00:00

dput(x) structure(list(Date = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L,

  • 0
    dput(x)
structure(list(Date = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 
3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L), .Label = c("1/1/2012", 
"2/1/2012", "3/1/2012", "4/1/2012", "5/1/2012", "6/1/2012"), class = "factor"), 
    Continent = structure(c(3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 
    3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L), .Label = c("Asia", "Europe", 
    "South America"), class = "factor"), Score = c(10L, 4L, 9L, 
    1L, 9L, 3L, 10L, 0L, 0L, 10L, 4L, 9L, 10L, 4L, 9L, 0L, 0L, 
    5L), Country = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 
    3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("Brasil", 
    "China", "Germany"), class = "factor"), mean = c(6.83333333333333, 
    3.5, 5.83333333333333, 6.83333333333333, 3.5, 5.83333333333333, 
    6.83333333333333, 3.5, 5.83333333333333, 6.83333333333333, 
    3.5, 5.83333333333333, 6.83333333333333, 3.5, 5.83333333333333, 
    6.83333333333333, 3.5, 5.83333333333333), sd = c(4.91596040125088, 
    3.33166624979154, 3.81663027639129, 4.91596040125088, 3.33166624979154, 
    3.81663027639129, 4.91596040125088, 3.33166624979154, 3.81663027639129, 
    4.91596040125088, 3.33166624979154, 3.81663027639129, 4.91596040125088, 
    3.33166624979154, 3.81663027639129, 4.91596040125088, 3.33166624979154, 
    3.81663027639129), outlier1 = c(FALSE, FALSE, FALSE, TRUE, 
    TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, 
    FALSE, FALSE, TRUE, TRUE, FALSE)), .Names = c("Date", "Continent", 
"Score", "Country", "mean", "sd", "outlier1"), row.names = c(NA, 
-18L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x0000000005e70788>)

I have calculated mean, sd and outlier1 for each country. I would like apply a outlier_score to each country to rank them. Can Somebody give any pointers how to calculate the outlier score on this data set?

  • 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-18T00:58:30+00:00Added an answer on June 18, 2026 at 12:58 am
    # if the record is an outlier,
    # take the absolute value of the difference
    # between the score and the mean
    # otherwise leave it blank
    x$distance.to.mean <- ifelse( x$outlier1 , abs( x$Score - x$mean ) , NA )
    
    # for all records with non-missing distances,
    # add a `rank` variable based on its order in the data
    x[ !is.na( x$distance.to.mean ) , 'rank' ] <- 
        rank( x[ !is.na( x$distance.to.mean ) , 'distance.to.mean' ] )
    
    # see the result
    x
    
    # sum up the number of outliers in each country grouping
    outliers.by.country <- tapply( x$outlier1 , x$Country , sum )
    
    # take a look at those counts
    outliers.by.country
    
    # create a vector of all matches to the outliers.by.country table
    y <- match( x$Country , names( outliers.by.country ) )
    
    # and merge on the contents of the outliers.by.country table to x
    x$sum.outliers <- 
        outliers.by.country[ y ]
    
    # sort by the sum if you like
    x <- x[ order( x$sum.outliers , decreasing = TRUE ) , ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

dput(df) structure(list(Month = structure(c(15248, 15522), class = Date), Value = c(1, 3)), .Names =
> dput(head(t)) structure(list(Team = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = Union, class
I have this data frame: dput(df2) structure(list(Receiver = structure(c(4L, 3L, 2L, 1L), .Label =
I have a data frame is like this: dput(xx) structure(list(TimeStamp = structure(c(15705, 15706), class
I have the following dataframe: > dput(py6s_pwc_16) structure(list(source = c(AERONET, BIGF, MODIS), ndvi_real =
I have a fairly simple data.frame dput(x), below: x <- structure(list(variable = c(a, b,
I have a melted data.frame, dput(x), below: ## dput(x) x <- structure(list(variable = structure(c(1L,
Here's the data.frame in question : sample <- dput(df) structure(c(6, 5, 5, 4, 4,
working with a data frame x Date Val 1/1/2012 7 2/1/2012 9 3/1/2012 20
I have a zoo class data set loaded into R and I am trying

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.