R: Error in bind_rows_ (x, .id), Argument 111 when combining dataframes


I am using R version 3.4.3. I have two data.frames of different sizes with some common columns and others not. I want to combine both data frames keeping the different columns so that NAs appear in the part of the data frame where that column was not present. I'm using the "dplyr" library and the "bind_rows" function:

    mydata_combine <- bind_rows(mydata,mydata2)

I get the following error:

   Error in bind_rows_(x, .id) : Argument 111 must be length 1309, not 2618

where the common columns of my data frames are the same size and type, and:

    > is.data.frame(mydata)
    [1] TRUE
    > is.data.frame(mydata2)
    [1] TRUE
    > ncol(mydata)
    [1] 127
    > ncol(mydata2)
    [1] 112
    > nrow(mydata)
    [1] 1309
    > nrow(mydata2)
    [1] 364

Could someone explain why I get this error? I have used this function many times with similar data and had never had such an error. Thanks!

asked by Ele Begé 04.04.2018 в 10:53

1 answer


The problem is solved by using the rbind.fill() function of the "plyr" package:

mydata_combine <- rbind.fill(mydata,mydata2)
answered by 04.04.2018 / 13:48