octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dataframe dereferencing


From: CdeMills
Subject: Re: dataframe dereferencing
Date: Thu, 2 Sep 2010 07:24:10 -0700 (PDT)


Judd Storrs-2 wrote:
> 
> On Thu, Sep 2, 2010 at 4:35 AM, CdeMills
> <address@hidden>wrote:
> 
>> x(1:3, 1:2)(:).cell
>> y = x(1:3, 1:2)(:)
>> z = y.cell
>>
> 
> I understand why you are doing this, but one thing to be aware of is that
> the idiomatic way to do casting is to call a constructor. e.g. this is how
> I
> would naively approach this based on how things are done in Matlab:
> 
> cell(x(1:3, 1:2)(:))
> y = x(1:3, 1:2)(:)
> z = cell(y)
> 
> For user-written classes, I think you can either provide @foo/foo.m or
> @dataframe/foo.m, but I'm not 100% certain because I haven't done this in
> a
> while.
> 
> I'm very interested in dataframe but I haven't had a chance to look at it
> yet. Based only on this thread one question I had was whether dataframe
> already implement cell-style "{}" indexing in addition to the "()"
> indexing?
> If not, maybe that could be used to distinguish between the "I want the
> data" and "I want a dataframe subset" uses.
> 
> x(1:3) # <-- return data if appropriate
> x{1:3} # <-- return truncated dataframe
> 
> Then these may all do slightly different things:
> 
> z = x{1:3, 1:2}{:}
> z = x(1:3, 1:2)(:)
> z = x{1:3, 1:2}(:)
> 
> 
> --judd.
> 
> 

For the first point: cell() is already a builtin function, so you have to
emulate a method call on a dataframe object, this is the purpose of
x.cell(some_range).

For the second point, the idea is that a dataframe mimics as much as
possible a matrix. Access rules on a dataframe are:
- if all data are numeric, select the columns and horzcat() the content. If
types are different, demotion takes places: mixing double and uint32 results
in a uint32 matrix.
- if data are not mixable (strings and numeric), the result is a subset of
type dataframe.
- to avoid demotion, version 0.5 introduced the 'as' operator. So
x.as.double(:, ["Column1"; "Column2"]) will return a matrix of doubles 
- to force the output to be a dataframe, use x.dataframe(some_range)
- last but not least, to use some numerical function expecting a numerical
matrix, use 
some_func(x(:, :)) : this will invoque subsref, and behave like in the first
rule.

This way, as we're trying to emulate a matrix, there is no implementation of
access rules through {}, as this doesn't make sense on matrices.

Regards

Pascal
-- 
View this message in context: 
http://octave.1599824.n4.nabble.com/dataframe-dereferencing-tp2494732p2524246.html
Sent from the Octave - Maintainers mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]