1

Im a bit stuck with a similar question to this one: Fill and empty data frame in R.

I have a very large output from various parts of my model which are run on for loops. The output is summarized in a single row with the relevant values.

tab2<-cbind (tab.info, tab1, summary)
str (tab2)
 chr [1, 1:21] "EBF" "H2O" "517" "51" "8050" "1e-04" "0.7" "3" "poisson" "0.704811263414307" ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:21] "V1" "V2" "n.obs" "n.sites" ...

I want to bind this row to an empty matrix model.results but every time I do this, the headers disappear and new rows wont be added on.

model.results <- data.frame(Landclass= character(0), Resource = character(0), n.obs= integer(0), n.sites= integer(0), n.trees= integer(0), 
                            learning.rate= numeric(0), bag.fraction= numeric(0),tree.complexityn.trees= integer(0), 
                            family= character(0), mean.deviance= numeric(0), mean.residual.dev= numeric(0), 
                            cv.correlation= numeric(0), correlation.mean= numeric(0), correlation.se= numeric(0), 
                            alt= numeric(0),bio1= numeric(0), bio12= numeric(0), distance= numeric(0), 
                            lat= numeric(0), lon= numeric(0), ndvi= numeric(0))


model.results<-rbind(tab2)
> model.results
   V1  V2 n.obs n.sites   V5    V6  V7 V8      V9               V10               V11               V12              V13
1 EBF H2O   517      51 8050 1e-04 0.7  3 poisson 0.704811263414307 0.604995121681059 0.366088115802614 0.19475244146538
                 V14              V15             V16              V17              V18              V19              V20
1 0.0456416292878939 9.89162170209534 2.2197735719569 10.4033471885163 1.98746621353663 27.1499947776137 13.3029282417277
               V21
1 35.0448683045534

Any suggestions?

Community
  • 1
  • 1
I Del Toro
  • 913
  • 4
  • 15
  • 36
  • 2
    The `model.results` object is a `data.frame` and not a `matrix`. Do you know the difference? The line `model.results<-rbind(tab2)` removes the old `model.results` object, since you are redefining it. Furthermore, it makes little sense to use `rbind` with just one argument. To bind by row two or multiple objects use `rbind(obj1,obj2,obj3,...)`. Be careful that the column names of all the objects must be the same. – nicola Mar 01 '16 at 11:13

0 Answers0