Thread Subject: datasets -- desirable behaviour?

Subject: datasets -- desirable behaviour?

From: James

Date: 30 Jun, 2011 09:44:10

Message: 1 of 3

I'm wondering if this is a case of sloppy coding or something that shouldn't be happening

% Create a dataset
ds = dataset({{'Henri'; 'John'; 'James'}, 'Name'}, {[175; 168; 180] 'Height'});
ds.Name = nominal(ds.Name);

% Remove a name
ds = ds(ds.Name ~= 'James', :);

%..and it's still there (in a sense)
getlabels(ds.Name)

% I need to rename to solve the problem
ds.Name = nominal(ds.Name);
getlabels(ds.Name)

Subject: datasets -- desirable behaviour?

From: Peter Perkins

Date: 30 Jun, 2011 20:12:02

Message: 2 of 3

James, the behavior of NOMINAL here is intentional. Just because you've
removed all elements whose value is 'James', doesn't mean the vector no
longer "knows" that 'James' is a value it should care about. Imagine,
for example, that you had done this:

 > ds1 = ds(ds.Height < 180, :);
 > summary(ds1.Name)

 > ds2 = ds(ds.Height < 170, :);
 > summary(ds2.Name)

You'd want both of thos to return 3 counts, right? Otherwise the length
of table would be data-dependent. That's a bit artificial, but tere are
lots of other similar situations.

The DROPLEVELS method, with one input, will remove any levels for which
there are no elements having that value. So another way to do what you
did would be

    ds.Name = droplevels(ds.Name);

Hope this helps.


On 6/30/2011 5:44 AM, James wrote:
> I'm wondering if this is a case of sloppy coding or something that
> shouldn't be happening
>
> % Create a dataset
> ds = dataset({{'Henri'; 'John'; 'James'}, 'Name'}, {[175; 168; 180]
> 'Height'});
> ds.Name = nominal(ds.Name);
>
> % Remove a name
> ds = ds(ds.Name ~= 'James', :);
>
> %..and it's still there (in a sense)
> getlabels(ds.Name)
>
> % I need to rename to solve the problem
> ds.Name = nominal(ds.Name);
> getlabels(ds.Name)

Subject: datasets -- desirable behaviour?

From: james bejon

Date: 30 Jun, 2011 20:49:10

Message: 3 of 3

It does help. Thanks. I wasn't aware of the droplevels method.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
dataset James 30 Jun, 2011 05:44:12
getlabels James 30 Jun, 2011 05:44:12
filter James 30 Jun, 2011 05:44:12
remove James 30 Jun, 2011 05:44:12
rssFeed for this Thread

Contact us at files@mathworks.com