Let's say I have data.frame like:
a <- c(1:10,1:10,1:10,1:10,1:10,1:10,1:10,1:10,1:10,1:10) df <- data.frame(a,rnorm(100))
And I want to write a csv file for each x value. Can this be done with ddply?
I can already do this with a for loop on several lines ... but I'm curious if this can be done with ddply.
for (x in 1:nrow(unique(df["a"]))) { tmp <- unique(df["a"]) tmp2 <- paste(tmp[x,],".csv", sep="") write.table(subset(df, a == tmp[a,], drop=T),file=tmp2, sep=",", row.names=F) }
source share