You could 'split' the dataframe and then write out each element: something like
x <- split(data.info, data.info$station.id) for (i in names(x)) write.csv(x[[i]], file=paste(i, ".csv", sep="")) On Tue, Feb 17, 2009 at 10:11 PM, CJ Rubio <cjru...@kongju.ac.kr> wrote: > > it works perfectly!!!! thank you for your help.... > > what if i want to seperate each stations data and save in a .csv file?? > while i'm asking you these i'm also finding some ways to do so.. > > thank you again. > > > > > > jholtman wrote: >> >> try using: >> >> data.info <- rbind(data.info, cbind(station.id, year, date, >> max.discharge)) >> >> On Tue, Feb 17, 2009 at 9:26 PM, CJ Rubio <cjru...@kongju.ac.kr> wrote: >>> >>> i have the following constructed and running very well,, thanks to Gabor >>> Grothendieck for his help. >>> >>>>data.info <- c("station.id", "year", "date", "max.discharge") >>>> >>>> for(i in 1:num.files) { >>> + station.id <- substring(data[i], 1,8) >>> + DF <- read.table(data[i], sep=",", blank.lines.skip = TRUE) >>> + z <- zoo(DF[,4], as.Date(as.character(DF[,3]), "%m/%d/%Y")) >>> + f <- function(x) time(x) [which.max(x)] >>> + ix <- tapply(z, floor(as.yearmon(time(z))),f) >>> + year <- (1988:2005) >>> + date <- time(z[ix]) >>> + max.discharge <- coredata(z[ix]) >>> + data.info <- rbind(data.info, c(station.id, year, date, max.discharge)) >>> + } >>> >>> my problem with my code occurs in the part where I arrange my results.. >>> after running this code, i get this warning: >>> >>> Warning message: >>> In rbind(data.info, c(station.id, year, date, max.discharge)) : >>> number of columns of result is not a multiple of vector length (arg 1) >>> >>> >>> i can't figure out what to do to produce the result i wanted: >>> (for each station, it should look like this:) >>> >>> data.info "station.id" "year" "date" "max.discharge" >>> "01014000" 1988 "1988-11-07" 4360 >>> "01014000" 1989 "1989-05-13" 20000 >>> "01014000" 1990 "1990-10-25" 9170 >>> "01014000" 1991 "1991-04-22" 12200 >>> "01014000" 1992 "1992-03-29" 11800 >>> .... >>> "01014000" 2005 "2005-04-04" 22100 >>> >>> thanks in advence for your help.. >>> -- >>> View this message in context: >>> http://www.nabble.com/rbind%3A-number-of-columns-of-result-is-not-a-multiple-of-vector-length-%28arg-1%29-tp22070942p22070942.html >>> Sent from the R help mailing list archive at Nabble.com. >>> >>> ______________________________________________ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> >> >> -- >> Jim Holtman >> Cincinnati, OH >> +1 513 646 9390 >> >> What is the problem that you are trying to solve? >> >> ______________________________________________ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> > > -- > View this message in context: > http://www.nabble.com/rbind%3A-number-of-columns-of-result-is-not-a-multiple-of-vector-length-%28arg-1%29-tp22070942p22071324.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.