Skip to content
Prev 79273 / 398502 Next

cbind/rbind and NULL

I'm trying to understand why I can rbind but not cbind dataframes to
NULLs.

	For 'cbind' ('rbind'), vectors of zero length (including 'NULL')
     are ignored unless the result would have zero rows (columns),  for
     S compatibility. (Zero-extent matrices do not occur in S3 and are
     not ignored in R.)

Since NULL is a vector of length 0, should it not be ignored for both
cbind and rbind? If not, then shouldn't it fail for the same reason for
both functions?
Murder Assault UrbanPop Rape
Alabama          13.2     236       58 21.2
Alaska           10.0     263       48 44.5
...
Error in data.frame(..., check.names = FALSE) : 
        arguments imply differing number of rows: 50, 0

Also, cbinding vectors works:
[,1]
 [1,] 13.2
 [2,] 10.0
 [3,]  8.1

But not if USArrests is a dataframe:
Error in data.frame(..., check.names = FALSE) : 
        arguments imply differing number of rows: 50, 0

Thanks, 
Robert
_              
platform i386-pc-mingw32
arch     i386           
os       mingw32        
system   i386, mingw32  
status                  
major    2              
minor    2.0            
year     2005           
month    10             
day      06             
svn rev  35749          
language R