Skip to content

odd behavior when multiplying data frame by an element

1 message · Patrick Burns

#
I think it might be up for discussion whether or not
there is a bug in here somewhere.

 > mat10 <- matrix(1:6, 3)
 > mat10 * 1:12
Error: dims [product 6] do not match the length of object [12]
 > data.frame(mat10) * 1:12
  X1 X2
1  1 16
2  4 25
3  9 36
 > version
               
_                                                              
platform       
i386-pc-mingw32                                                
arch           
i386                                                           
os             
mingw32                                                        
system         i386, 
mingw32                                                  
status         Under development 
(unstable)                                   
major          
2                                                              
minor          
9.0                                                            
year           
2008                                                           
month          
11                                                             
day            
22                                                             
svn rev        
47006                                                          
language       
R                                                              
version.string R version 2.9.0 Under development (unstable) (2008-11-22 
r47006)


It seems dangerous to me that there is not at least
a warning in the data frame case.  I think I'd prefer
an error like the matrix case.

Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
markleeds at verizon.net wrote: