Introduce missing values into a vector or data frame
Source:R/FUNCTIONS_GENERATE_DATA.R
generate_missing.RdRandomly replaces a fixed number of values with NA,
either in a vector or across every column of a data frame independently.
Value
The input object with missing values replaced by NA.
Returns the same type as the input (vector or data frame).
Examples
generate_missing(rnorm(10), missing = 5)
#> [1] -0.5569 NA 1.0980 NA NA NA -0.2768 0.7523 1.0451 NA
generate_missing(generate_data(nrow = 10, ncol = 2), missing = 5)
#> X1 X2
#> 1 NA NA
#> 2 -0.4388 NA
#> 3 NA 0.9218
#> 4 NA NA
#> 5 NA 0.3606
#> 6 -1.5297 -1.3665
#> 7 -0.2401 NA
#> 8 1.1533 -0.6981
#> 9 NA -0.8304
#> 10 -1.3230 NA