0

I am trying to fix my code. I am not sure what I am doing wrong, but the code is supposed to retrieve all values from vector x that are:

  • larger than two standard deviations from the average

or

  • smaller than two standard deviations from the average.
set.seed(2) x = rnorm(10000) average = mean(x) upper_bound = average + sd(average) lower_bound = average - sd(average) boolean_vector = x < lower_bound | x > upper_bound y = x[boolean_vector] 
1
  • 2
    Your definitions of the bounds should be sd(x) instead of sd(average). Commented Feb 20, 2021 at 4:20

1 Answer 1

1

You can not take the standard deviation of an integer so instead of

upper_bound = average + sd(average) lower_bound = average - sd(average) 

you would do

upper_bound = average + sd(x) lower_bound = average - sd(x) 

plus you want to be 2 standard deviations away so it would be

upper_bound = average + 2*sd(x) lower_bound = average - 2*sd(x) 
Sign up to request clarification or add additional context in comments.

Comments