Skip to content

rbind: number of columns of result is not a multiple of vector length (arg 1)

4 messages · CJ Rubio, jim holtman

#
i have the following constructed and running very well,, thanks to Gabor
Grothendieck for his help.
+ 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..
#
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 <cjrubio at 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:

  
    
#
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 <cjrubio at kongju.ac.kr> wrote: