[datatable-help] Subsetting that behaves right for both data frames and data.tables?
Timothée Carayol
timothee.carayol at gmail.com
Wed Jul 20 13:44:25 CEST 2011
Sorry --
subset() was a poor idea, as it will return a data.frame even if the
argument is a data.table..
2011/7/20 Timothée Carayol <timothee.carayol at gmail.com>
> Hi--
>
> You can use the subset() command with the select= option; not sure it's the
> best solution, though.
>
> Timothee
>
>
> On Wed, Jul 20, 2011 at 12:26 PM, Chris Neff <caneff at gmail.com> wrote:
>
>> I have a function where I pass a data frame and some variable names to
>> calculate statistics on. However, I am at a loss as to how to write it
>> correctly so that both data.frame and data.table work with it. If I have:
>>
>> DF = data.frame(x=1:10,y=2:11,z=3:12)
>>
>> DT = data.table(DF)
>>
>> var.names = c("x","y")
>>
>>
>> I can do the following things to subset:
>>
>> DT[,var.names,with=FALSE]
>> DF[,var.names]
>>
>>
>> but of course DT[,var.names] won't give me back what I want, and
>> DF[,var.names,with=FALSE] returns an error because with doesn't exist there.
>> So how do I do this?
>>
>> Thanks,
>> -Chris
>>
>>
>>
>> _______________________________________________
>> datatable-help mailing list
>> datatable-help at lists.r-forge.r-project.org
>>
>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20110720/e8c6c6ed/attachment.htm>
More information about the datatable-help
mailing list