I have the following tibble and I want to sample the arrival time for every passenger with a poisson distribution rpois(n, lambda)
.
# A tibble: 3 x 4
flight terminal passengers arrivaltime
<chr> <chr> <dbl> <dbl>
1 LX123 A 3 120
2 UA1 B 2 130
The final tibble should look like this and every row represents a single passenger with the arrival time being a sample from the poisson distribution with lambda being the arrival time of the flight in the first tibble.
# A tibble: 3 x 4
flight terminal arrivaltime
<chr> <chr> <dbl>
1 LX123 A 125
2 LX123 A 115
3 LX123 A 118
4 UA1 B 129
5 UA1 B 132
I already have the following code which calculates the rpois values and applies it to the tibble:
f = function(x, output){
n = as.integer(x[[3]])
lambda = as.integer(x[[4]])
rpois(n, lambda)
}
apply(tibble, MARGIN = 1, FUN = f)
My question is now how to complete my approach to create the second tibble. Since the dataset used is huge, fast computation is an issue.