Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Conditional Maximum
Replies: 2   Last Post: Nov 24, 2012 3:54 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 8,098
Registered: 6/7/07
Re: Conditional Maximum
Posted: Nov 24, 2012 2:13 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 11/24/2012 12:07 PM, Rahat wrote:
> I have 3 columns in my database:
>
> ID Year Tenure
> 12 1992 1

.
> 12 1995 4
> 225 2001 1

...
> 225 2006 6
> 3045 2009 1

...

> I want to keep IDs with a tenure >=5 years. For that matter I want to
> create a 4th column containing "Maximum Tenure" against each id such that:
>
> ID Year Tenure MaxTenure
> 12 1992 1 4
> 12 1993 2 4
> 12 1994 3 4
> 12 1995 4 4
> 225 2001 1 6

...

ix=[diff([x(:,1)])>1 ;true];
z=[];for i=1:length(maxT),z=[z;repmat(maxT(i),maxT(i),1)];end
x(:,4)=z;

There's got to be a more clever way to do the expansion--I've got brain
cramp at the moment, though, apparently...

--




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.