0
$\begingroup$

I have a dataset of 59 years worth of daily rainfall data.

I'd like to resample the data by 6 randomly selected years 1,000 times, using the entire year of data for each of the 6 years (so 2190 observations in total).

Currently, the line of code I'm using only selects a random set of observations but not necessarily within the same year.

duration6 <- duration[sample(1:nrow(duration$WrYear), 2190, replace=TRUE),]

Any help in the right direction would be appreciated!

  • Thanks
$\endgroup$
0
$\begingroup$

You need to index the rows by whether they are in the year of interest.

duration6 <- duration[duration$WrYear %in% sample(unique(duration$WrYear), 6, replace=TRUE),]

You are to randomly sample 6 of the 59 years, and choosing the rows that are in one of those 6 years.

$\endgroup$
  • $\begingroup$ Ok, will do, thank you! $\endgroup$ – S. Garvis Apr 17 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.