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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:04:19+00:00 2026-06-03T16:04:19+00:00

I have looked at a set of data and decided it would be good

  • 0

I have looked at a set of data and decided it would be good to remove outliers, with an outlier having the definition of being 2SD away from the mean.

If I have a set of data, say 500 rows with 15 different attributes, how can I remove all the rows which have 1 or more attribute which is 2 standard deviations away from the mean?

Is there an easy way to do this using R?
Thanks,

  • 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-03T16:04:20+00:00Added an answer on June 3, 2026 at 4:04 pm

    There’s probably lots of ways and probably add on packages to deal with this. I’d suggest you try this first:

    library(sos); findFn("outlier")
    

    Here’s a way you could do what your asking for using the scale function that can standardize vectors.

    #create a data set with outliers
    set.seed(10)
    dat <- data.frame(sapply(seq_len(5), function(i) 
        sample(c(1:50, 100:101), 200, replace=TRUE)))
    
    #standardize each column (we use it in the outdet function)
    scale(dat)
    
    #create function that looks for values > +/- 2 sd from mean
    outdet <- function(x) abs(scale(x)) >= 2
    #index with the function to remove those values
    dat[!apply(sapply(dat, outdet), 1, any), ]
    

    So in answering your question yes there is an easy way in that the code to do this could be boiled down to 1 line of code:

    dat[!apply(sapply(dat, function(x) abs(scale(x)) >= 2), 1, any), ]
    

    And I’m guessing there’s a package that may do this and more. The sos package is terrific (IMHO) for finding functions to do what you want.

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

Sidebar

Related Questions

I have looked for some explanation on the exact usages for the set of
Have looked quite hard for this answer but having no luck. I have 3
I have looked at several options like: * http://blog.waynehartman.com/archive/2012/01/07/uistoryboard-on-ios-5-the-good-the-bad-and-the.aspx * UIPopoverController Anchor Position *
I have some data and want to create some dynamic charts. I have looked
What is a good pattern for sharing data between related views?. I have an
Say I have a QTableWidget with 10 columns. I set data in the table
I have looked through the whole set of Oracle Database 11g Release 2 (11.2)
I have looked at Storing Form Data as a Session Variable , but nobody
I have a data set that is organized in the following manner: Timestamp|A0001|A0002|A0003|A0004|B0001|B0002|B0003|B0004 ...
I have a WPF ComboBox that binds to a set of data. I do

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.