Skip to content

Shallow copies

1 message · Simon Urbanek

#
On Sep 30, 2014, at 5:20 PM, Matthieu Gomez <gomez.matthieu at gmail.com> wrote:
No. Subsetting a vector always requires a copy by definition*. Each column in a dataframe and each matrix is a vector, so any subset thereof always requires a copy no matter what you do.
Subsetting columns of a dataframe only requires a copy of the dataframe vector itself which is small by comparison (at least for datasets that use data frames).

Cheers,
Simon

* - you could try to do tricks where you fake a copy with things like COW mmaps, but you still need to have a copy conceptually. There are other tricks like deferred execution (you don't actually compute the result but only store the recipe for creating it), but those are more specialized and not generally available.