Guest User

Untitled

a guest
Apr 25th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. rainfall_values = c(270.8, 150.5, 486.2, 442.3, 397.7,
  2. 593.4191, 165.608, 116.9841, 265.69, 217.934, 358.138, 238.25,
  3. 449.842, 507.655, 344.38, 188.216, 210.058, 153.162, 232.26,
  4. 266.02801, 136.918, 230.634, 474.984, 581.156, 674.618, 359.16
  5. )
  6.  
  7. #brute force
  8. sample_size=10 #number of years included in each sample
  9. n_replicates=1000 #number of total samples calculated
  10. target=mean(rainfall_values)*1.1 #try to find samples that are 10% wetter than historical mean
  11. tolerance=0.01*target #how close do we want to meet the target specified above?
  12.  
  13. #create large matrix of samples
  14. sampled_DF=t(replicate(n_replicates, sample(x=rainfall_values, size=sample_size, replace=T)))
  15. #calculate mean for each sample
  16. Sampled_mean_vals=apply(sampled_DF,1, mean)
  17. #create DF only with samples that meet the criteria
  18. Sampled_DF_on_target=sampled_DF[Sampled_mean_vals>(target-tolerance)&Sampled_mean_vals<(target+tolerance),]
Add Comment
Please, Sign In to add comment