vendredi 16 juin 2017

generate random sequences of NA of random lengths in a vector

I want to generate missing values in a vector so that the missing value are grouped in sequences, to simulate periods of missing data of different length.

Let's say I have a vector of 10 000 values and I want to generate 12 sequences of NA at random locations in the vector, each sequence having a random length L between 1 and 144 (144 simulates 2 days of missing values at timestep 10 min). The sequences must not overlap.

How can I do that? Thanks. I tried to do it combining lapply and seq but with no success.

expected output example:

# 1 2 3 5 2 NA NA  5 4 6 8 9 10 11 NA NA NA NA NA NA 5 2 NA NA NA




Aucun commentaire:

Enregistrer un commentaire