Given the following sample data (R data frame), I would like to create folders for each group, containing folders for each sub group, (finally) containing a CSV file with corresponding values val1, using R.
Grp <- c("A", "A", "A", "B", "B", "B")
Subgrp <- c("k", "l", "m", "n", "n", "n")
val1 <- c(1.1, 3.2, 4.5, 5.6, 6.7, 7.7)
df <- data.frame(Grp, Subgrp, val1)
This is what I have tried so far, creating a CSV file for each sub-group.
by(df, df$Subgrp, FUN=function(i) write.csv(i,paste0("C:/Temp/",i$Subgrp[1], ".csv")))
I need to iterate this for large data frame. What is the most efficient way of achieving this? I am open for suggestions based on looping and dpyr.