I have run into a problem and managed to solve it with a hack and I wish to understand the problem and hopefully get rid of the hack.
I tried recreating the problem to no avail, so words will have to suffice here.
I am trying to rbind
two dataframes in R, the result of which must again be a dataframe, not a list. I use rbind
in most of my scripts and have never had an issue before.
However, today I applied rbind to two dataframes, say foo
and bar
and it returned a list
foobar
. The hack I use to fix this is to force-convert foo
and bar
to dataframes again as follows:
rbind(data.frame(foo), data.frame(bar))
This works, but I would like to know why I have to convert it explicitly when both foo
and bar
are already data.frames.
My question is then in what 'general' scenarios would rbind
return a list
when both inputs are data.frames?
I tried debugging it by looking at rbind(A,A)
and rbind(B,B)
. Both times it returns a dataframe and not a list
. Why then would rbind(A,B)
return a list
?
Thanks!