Assume the following data structure with a bunch of other data columns in the same tibble (not shown here) - the two columns in question are what's important.
data <- tibble(id = c(1,2,3,4,5,6,7,8,9), email = c(rep('aaa@aaa.com',3), rep('bbb@bbb.com', 3), rep('ccc@ccc.com', 3)))
I'm trying to 1) write individual xlsx files based on the email column (1 per email address) and 2) write the individual ids for an email into separate tabs in the xlsx.
This is what I have so far, but it's not fully implementing what I need.
for(i in unique(data$email)){
print(data %>% filter(email == i))
for(j in unique(data %>% filter(email == i) %>% select(id))){
print(length(j))
for(k in j){
write.xlsx(data %>% filter(id == k), file = paste('./test_', k, '.xlsx'), sheetName = names(j)[k], append = TRUE)
}
}
}