R Error in rbind : numbers of columns of arguments do not match (2 Examples)
In this article you’ll learn how to debug the “Error in rbind(deparse.level, …) : numbers of columns of arguments do not match” in the R programming language.
Creation of Example Data
df1 <- data.frame(col1 = letters[1:4], # Construct two data sets col2 = 4:1, col3 = 8:5, col4 = letters[8:5]) df1 # col1 col2 col3 col4 # 1 a 4 8 h # 2 b 3 7 g # 3 c 2 6 f # 4 d 1 5 e |
df1 <- data.frame(col1 = letters[1:4], # Construct two data sets col2 = 4:1, col3 = 8:5, col4 = letters[8:5]) df1 # col1 col2 col3 col4 # 1 a 4 8 h # 2 b 3 7 g # 3 c 2 6 f # 4 d 1 5 e
df2 <- data.frame(col1 = LETTERS[1:4], col3 = 18:15) df2 # col1 col3 # 1 A 18 # 2 B 17 # 3 C 16 # 4 D 15 |
df2 <- data.frame(col1 = LETTERS[1:4], col3 = 18:15) df2 # col1 col3 # 1 A 18 # 2 B 17 # 3 C 16 # 4 D 15
Example 1: Replicating the Error Message – numbers of columns of arguments do not match
rbind(df1, df2) # rbind function of Base R # Error in rbind(deparse.level, ...) : # numbers of columns of arguments do not match |
rbind(df1, df2) # rbind function of Base R # Error in rbind(deparse.level, ...) : # numbers of columns of arguments do not match
Example 2: Debugging the Error Message – numbers of columns of arguments do not match
install.packages("dplyr") # Install & load dplyr library("dplyr") |
install.packages("dplyr") # Install & load dplyr library("dplyr")
bind_rows(df1, df2) # bind_rows function of dplyr package # col1 col2 col3 col4 # 1 a 4 8 h # 2 b 3 7 g # 3 c 2 6 f # 4 d 1 5 e # 5 A NA 18 <NA> # 6 B NA 17 <NA> # 7 C NA 16 <NA> # 8 D NA 15 <NA> |
bind_rows(df1, df2) # bind_rows function of dplyr package # col1 col2 col3 col4 # 1 a 4 8 h # 2 b 3 7 g # 3 c 2 6 f # 4 d 1 5 e # 5 A NA 18 <NA> # 6 B NA 17 <NA> # 7 C NA 16 <NA> # 8 D NA 15 <NA>
Related Articles & Further Resources
In the following, you can find some additional resources on topics such as coding errors and numeric values.