From lawrence.michael at gene.com  Fri Aug 21 08:02:18 2015
From: lawrence.michael at gene.com (Michael Lawrence)
Date: Thu, 20 Aug 2015 23:02:18 -0700
Subject: [Rd] sequence divided by data.frame
In-Reply-To: <CAMMJQ0ZfrKKJezFr0fUaHYW8u4b3GKOA=KXxBQ+-eJCMb2LQNw@mail.gmail.com>
References: <CAMMJQ0ZfrKKJezFr0fUaHYW8u4b3GKOA=KXxBQ+-eJCMb2LQNw@mail.gmail.com>
Message-ID: <CAOQ5NycfyOGFaa6WWOk1dZ+yYy0ovvzRbGGGHTUT99MDsG=caA@mail.gmail.com>

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 <otoomet at 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 at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] sequence divided by data.frame
Michael Lawrence