Solve R Error – Arguments Imply Differing Number of Rows (2 Examples)
This article shows how to handle the error message “arguments imply differing number of rows” in the R programming language.
Creation of Exemplifying Data
data(iris) # Iris flower as example data frame head(iris) # Sepal.Length Sepal.Width Petal.Length Petal.Width Species # 1 5.1 3.5 1.4 0.2 setosa # 2 4.9 3.0 1.4 0.2 setosa # 3 4.7 3.2 1.3 0.2 setosa # 4 4.6 3.1 1.5 0.2 setosa # 5 5.0 3.6 1.4 0.2 setosa # 6 5.4 3.9 1.7 0.4 setosa |
data(iris) # Iris flower as example data frame head(iris) # Sepal.Length Sepal.Width Petal.Length Petal.Width Species # 1 5.1 3.5 1.4 0.2 setosa # 2 4.9 3.0 1.4 0.2 setosa # 3 4.7 3.2 1.3 0.2 setosa # 4 4.6 3.1 1.5 0.2 setosa # 5 5.0 3.6 1.4 0.2 setosa # 6 5.4 3.9 1.7 0.4 setosa
Example 1: Reproduce Error: arguments imply differing number of rows
cbind(iris, 1:20) # Trying to apply cbind() function # Error in data.frame(..., check.names = FALSE) : # arguments imply differing number of rows: 150, 20 |
cbind(iris, 1:20) # Trying to apply cbind() function # Error in data.frame(..., check.names = FALSE) : # arguments imply differing number of rows: 150, 20
Example 2: Solve Error: arguments imply differing number of rows
cbind(iris, 1:nrow(iris)) # Properly applying cbind() function # Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1:nrow(iris) # 1 5.1 3.5 1.4 0.2 setosa 1 # 2 4.9 3.0 1.4 0.2 setosa 2 # 3 4.7 3.2 1.3 0.2 setosa 3 # 4 4.6 3.1 1.5 0.2 setosa 4 # 5 5.0 3.6 1.4 0.2 setosa 5 # 6 5.4 3.9 1.7 0.4 setosa 6 # ... ... ... ... ... ... ... |
cbind(iris, 1:nrow(iris)) # Properly applying cbind() function # Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1:nrow(iris) # 1 5.1 3.5 1.4 0.2 setosa 1 # 2 4.9 3.0 1.4 0.2 setosa 2 # 3 4.7 3.2 1.3 0.2 setosa 3 # 4 4.6 3.1 1.5 0.2 setosa 4 # 5 5.0 3.6 1.4 0.2 setosa 5 # 6 5.4 3.9 1.7 0.4 setosa 6 # ... ... ... ... ... ... ...