Adding rows to dataframe is easy with rbind
but i find that smartbind
is often better at handling exceptions such as dataframes with different columnnames and so on.
However Iteratively adding rows in smartbind
produces an additional row in some instances:
library(gtools)
alldf <- data.frame()
for (i in 1:3) {
df <- data.frame(x=i)
alldf<- smartbind(df,alldf)
}
smartbind
:
> alldf
x
1 3
2:1 2
2:2 1
2:3 1
rbind
:
> alldf
x
1 3
2 2
3 1
I don't have a clue why smartbind
does this, i've tried fiddling with removal of rownames rownames(alldf) <- NULL
, but it doesn't seem to change this. I can use rbind
instead for now, or i could inititalize the alldf
on the first loop, but it seems like a hassle. Plus, I sometimes prefer to use smartbind
so i would like to correct this.
Thanks for Reading