'I have a questions on writing function, loop, conditional in R
1.1 Create a function that returns the median if the number in the series is more than 2 times the standard deviation from the mean. Otherwise, it returns the same number. Generate 100 realizations of a variable x with x <- rnorm(100, mean = 2, sd = 1) and input the last number x[100] <- 5 to have at least one number that deviates from the mean two times. Print the function and the median in the console.
1.2 Make a function that tells us if the mean divided by the median is between 0.9 and 1.1. Use it on the whole dataframe using a supply function.
Why is the median and mean sometimes different?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
