[R] data.frame(1)*1:4 = 1?

Spencer Graves spencer.graves at structuremonitoring.com
Thu Apr 3 08:42:30 CEST 2014

Hello, All:

       What's the logic behind "data.frame(1)*1:4" producing a scalar 
1?  Or the following:

  data.frame(1:2, 3:4)*5:7
   X1.2 X3.4
1    5   21
2   12   20

       I stumbled over this, because I thought I was multiplying a 
scalar times a vector, and obtaining a scalar rather than the 
anticipated vector.  I learned that my "scalar" was in fact a data.frame 
with one row and one column.

       What am I missing?


More information about the R-help mailing list