data1=data.frame("Group1" = sample(1:2,100,r=T),
"Group2" = sample(c('a','b'),100,r=T),
"V1" = sample(1:3, 100, r=T),
"V2" = sample(0:1, 100, r=T),
"V3" = sample(1:5, 100, r=T),
"V4" = sample(1:2, 100, r=T))
data2=data.frame("Group1"=c(1,1,2,2),
"Group2"=c('a','b','a','b'),
"Size"=c(9,7,6,10),
"V1"=c(NA),
"V2"=c(NA),
"V3"=c(NA),
"V4"=c(NA))
I have 'data1' that contains my data. Then I have 'data2' which has 'Group1' and 'Group2' and 'Size'. What I wish for is to group my data by ('Group1' and 'Group2') and take a random sample of size 'Size' from 'data1' to fill in V1-V4 in data2.
The hopeful output would look like this but with the NA values filled in based on 'data1'
library(dplyr);library(tidyr)
data3= data2 %>%
uncount(Size)