Re: [R] use variable in for loop to name output files

2012-12-12 Thread MacQueen, Don
If your final goal is to write the csv files, and only the csv files, then then this (not tested) should do it. for (i in unique(appended$dp) ) { tmp <- subset(appended, dp==i & sampled==0) write.table(tmp, file= file.path('output', paste0('set',i,'.csv')), sep=',', row.names=FALSE

Re: [R] use variable in for loop to name output files

2012-12-10 Thread David Winsemius
On Dec 10, 2012, at 1:03 PM, john-usace wrote: Hi, This question should be simple to answer. I am a new R user. I have a data.frame called appended. I would like to break it into 7 smaller datasets based on the value of a categorical variable dp (which has values 1:7). I would like to nam

Re: [R] use variable in for loop to name output files

2012-12-10 Thread Rui Barradas
Hello, Try the following. set <- list() for (i in 1:7) { set[[i]] <- appended[which(appended$dp == i & appended$sampled == 0), ] fl <- paste0("output/set", i, ".csv") write.table(set[[i]], file = fl, sep = ",", row.name=F) } Hope this helps, Rui Barradas Em 10-12-2012 21:03, joh

[R] use variable in for loop to name output files

2012-12-10 Thread john-usace
Hi, This question should be simple to answer. I am a new R user. I have a data.frame called appended. I would like to break it into 7 smaller datasets based on the value of a categorical variable dp (which has values 1:7). I would like to name the smaller datasets set1, set2, set3,,set7. I d