Reputation: 10954
Here is an example where cbind
fails with an error when check.names=TRUE
is set.
data(airquality)
airQualityBind = cbind(airquality, airquality, check.names = TRUE)
Can anyone explain how to get this to work. I understand that cbind
is a call to data.frame
and the following works:
airQualityBind = data.frame(airquality, airquality, check.names = TRUE)
but I would like to understand why cbind
throws an error.
Upvotes: 3
Views: 5656
Reputation: 57686
Your cbind
call fails not because you have duplicated names, but because check.names
isn't a formal argument of cbind.data.frame
. It actually passes your check.names
argument down the line to data.frame
itself, and this fails because it also passes a check.names=FALSE
argument. Thus the error is one of duplicated formal arguments to data.frame
, not duplicated column names in the data frames.
To get it to work, just do cbind(airquality, airquality)
(which will result in duplicated column names) or data.frame(airquality, airquality)
(which will deduplicate them).
Upvotes: 3