This was surprisingly tricky! There may be a much easier way of doing this than I have.
library(tidyverse)
dat = tribble(
~Temp, ~RH, ~Experiments, ~Success,
15, 95, 3, 2,
10, 85, 2, 0,
5, 85, 4, 1
)
make_rows = function(temp, rh, times, n_succ){
df = data.frame(temp = temp, rh = rh)
df = slice(df, rep(1, each = times))
vec = c(rep("success", n_succ), rep("fail", nrow(df) - n_succ))
df %>% mutate(result = vec)
}
pmap_dfr(.l = dat,
.f = ~make_rows(temp = ..1, rh = ..2, times = ..3, n_succ = ..4))
Here I've written a function that takes a temperature, relative humidity, a number of repeats and the number of successes and creates a dataframe.
Then I map this function to the data from your original data frame, which seems to create the output that you wanted:
> pmap_dfr(.l = dat,
+ .f = ~make_rows(temp = ..1, rh = ..2, times = ..3, n_succ = ..4))
temp rh result
1 15 95 success
2 15 95 success
3 15 95 fail
4 10 85 fail
5 10 85 fail
6 5 85 success
7 5 85 fail
8 5 85 fail
9 5 85 fail