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