Generate synthetic vectors from their sampling distributions
generate_synthetic_object.Rd
One way of creating synthetic data is replicating sampling distribution of the variable. This function can be applied to dataframes, numeric or character/factor vectors and obtain an object of equal length with synthetic values.
Uso
generate_synthetic_object(obj, seed = NULL, n_news = NULL)
# S3 método para default
generate_synthetic_object(obj, seed = NULL, n_news = NULL)
# S3 método para numeric
generate_synthetic_object(obj, seed = NULL, n_news = NULL)
# S3 método para data.frame
generate_synthetic_object(obj, seed = NULL, n_news = NULL)
Argumentos
- obj
A dataframe, numeric vector or character/factor vector.
- seed
Specify seed when replication is desired.
- n_news
Length of the new vectors. By default, same length as input.
Ejemplos
generate_synthetic_object(mtcars)
#> # A tibble: 32 × 11
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 19.6 5 350. 133 3.16 3.26 19.2 0 0 4 2
#> 2 13.9 7 315. 246 3.93 1.52 17.8 1 0 3 4
#> 3 20 4 260. 74 2.93 3.66 17.9 1 1 3 3
#> 4 21.2 4 99.3 96 3.78 3.75 18.4 0 0 3 3
#> 5 14.5 7 160. 116 3.54 3.60 19.0 0 0 4 1
#> 6 19 4 180. 122 4.24 2.32 15.6 1 1 4 3
#> 7 15.2 5 359. 200 3.19 3.79 20.2 1 0 4 4
#> 8 15.9 7 426. 235 2.86 2.96 17.1 0 0 4 1
#> 9 16.2 5 104. 133 3.55 3.30 19.0 1 0 3 2
#> 10 21.3 7 82.2 110 3.11 3.90 19.9 0 0 4 3
#> # … with 22 more rows
generate_synthetic_object(mtcars$mpg)
#> [1] 12.3 15.5 22.9 16.0 14.4 13.0 30.6 18.2 24.3 19.6 27.5 11.6 20.9 28.5 29.8
#> [16] 19.6 19.9 18.0 14.3 22.4 17.3 22.1 12.8 12.5 17.8 26.2 16.6 28.1 20.7 19.5
#> [31] 14.8 26.6
generate_synthetic_object(as.factor(mtcars$cyl))
#> [1] 8 6 8 8 6 8 6 8 6 4 8 4 4 6 8 4 6 6 4 6 4 4 4 8 6 8 8 4 6 6 4 8
#> Levels: 4 6 8