Created
February 6, 2019 05:43
-
-
Save brshallo/6ef801f114f7ab4a3d63b1d61d8bf0a1 to your computer and use it in GitHub Desktop.
Overly fancy sample technique -- could just use `rbinom` rather than `sample` here
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` r | |
library(tidyverse) | |
tibble(x = runif(100), x_inv = 1 - x) %>% | |
mutate(event = map2_lgl(.x = x, | |
.y = x_inv, | |
~sample(c(TRUE, FALSE), | |
size = 1, | |
replace = TRUE, | |
prob = c(.x, .y)) | |
) | |
) | |
#> # A tibble: 100 x 3 | |
#> x x_inv event | |
#> <dbl> <dbl> <lgl> | |
#> 1 0.0366 0.963 FALSE | |
#> 2 0.280 0.720 FALSE | |
#> 3 0.475 0.525 TRUE | |
#> 4 0.151 0.849 FALSE | |
#> 5 0.978 0.0222 TRUE | |
#> 6 0.322 0.678 FALSE | |
#> 7 0.109 0.891 FALSE | |
#> 8 0.722 0.278 TRUE | |
#> 9 0.273 0.727 FALSE | |
#> 10 0.717 0.283 FALSE | |
#> # ... with 90 more rows | |
``` | |
<sup>Created on 2019-02-06 by the [reprex package](https://reprex.tidyverse.org) (v0.2.1)</sup> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment