I have n segmentation (0 to n-1) in a data. I know percentage of male in each segment.
How do I write a dynamic code to create arrays of segmentation and males without using loops?
For e.g. -
# datasize = 20, # segmentations = 2
N = 20
percent_each_segmentation = c(0.4, 0.6)
percent_male_per_segmentation = c(0.5, 0.25)
The desired output would look like
segmentation <- c(rep(0, 8), rep(1, 12))
# segmentation 0 - 0.4*20, segmentation 1 - 0.6*20
male <- c(rep(1, 4), rep(0, 4), rep(1, 3), rep(0, 9))
# male in segmentation 0 : 0.5*0.4*20, segmentation 1 : 0.25*0.6*20
tbl <- tibble(segmentation, male)