I have a dataset named data
Model Garage City
Honda C Chicago
Maruti B Boston
Porsche A New York
Honda
you could easily use a loop. that shouldn't be a problem with 100k or so lines.
x <- read.table(text = "Model, Garage, City
Honda, C, Chicago
Maruti, B, Boston
Porsche, A, New York
Honda, B, Chicago
Honda, C, New York", sep = ",", header = TRUE)
x
# Model Garage City
# Honda C Chicago
# Maruti B Boston
# Porsche A New York
# Honda B Chicago
# Honda C New York
library(dplyr)
you just iterate over all unique combinations of Model, Garage and City, filter
them from your data.frame
and export the temporary data.frame
to a csv table.
uni <- unique(x[,c("Model", "Garage", "City")])
for (j in 1:nrow(uni)) {
i <- uni[j,]
tmp <- x %>% filter(Model == i$Model, Garage == i$Garage, City == i$City)
write.table(tmp, paste(i$Model, "_", i$City, "_", i$Garage, ".csv"))
}