The first two behave as expected for vectors, because they are both
(at least implicitly) vectors in that usage. But a data.frame is a
tabular structure, so it's not obvious how to recycle it, nor does an
implicit coercion to matrix/vector seem justified. Thus, R attempts to
"recycle" the vector to fit the data.frame, even to the extent that
the vector is truncated (a warning could be justified here). You
should probably just be coercing to matrix in these situations. A
heterogeneous table is not really meant for arithmetic.

Michael

On Thu, Aug 20, 2015 at 5:08 PM, Ott Toomet <otoo...@gmail.com> wrote:
> Can anyone explain me the following behavior:
>
>> 1:2/1
> [1] 1 2
>
> -- makes sense
>
>> 1:2/matrix(1,1,1)
> [1] 1 2
>
> -- makes sense
>
>> 1:2/data.frame(a=1)
>   a
> 1 1
>
> -- why is this different?
>
> Best,
> Ott
>
> --
> Ott Toomet
>
> Visiting Researcher
> School of Information
> Mary Gates Hall, Suite 095
> University of Washington
> Seattle, WA 98195
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to