rsample-data

Using Replace function in sample with R


I'm trying to use sample function however encounturing some trouble. My objective is to have 500 samples from a normal distrubition and replace any numbers that are less than 5. I tried using replace function but not familiar with syntax and keep recieivng errors.

My normal distrubition code is:

 x <- rnorm(1000,10,4)

Solution

  • Remove values smaller than 5 from x and then sample 500 values

    sample(x[x > 5], 500)