'How can I merge an empty data frame and a data frame in R

I'm trying to merge to data frames like this:

data1 <- data.frame(hola = as.numeric(), toma = as.character())
data2 <- data.frame(hola = as.numeric(1), toma = as.character("cadenita"))
data1
data2

merge(data1, data2) 

But it just doesn't work, when I explore each I get:

> str(data1)
'data.frame':   0 obs. of  2 variables:
 $ hola: num 
 $ toma: Factor w/ 0 levels: 
> str(data2)
'data.frame':   1 obs. of  2 variables:
 $ hola: num 1
 $ toma: Factor w/ 1 level "cadenita": 1

I can see, it may be about the character column (toma) but I don't understand what's happening, can anyone give a hand???



Solution 1:[1]

Reopening long time later, but I bumped into the same question. Answer may be useful to others.

What you are looking for is appending the table, not merging. If you are using data.table, then rbindlist(list(data1, data2)) will do the job. Data1 may even be completely empty/undefined, i.e. data1 <- data.frame()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gicanzo