[R] A file manipulation question

Liaw, Andy andy_liaw at merck.com
Thu Mar 4 04:46:32 CET 2004


Say your data frame is `dat'.  Try:

    tapply(dat$Contract, dat$ID, max)

(The output is not a data frame, but that shouldn't be a problem...)

HTH,
Andy


> From: Greg Blevins
> 
> Hello R experts,
> 
> The following problem outstrips my current programming knowledge. 
> 
> I have a dataframe with two fields that looks like the following:
> 
> ID     Contract
> 
> 01     1
> 
> 01     1
> 
> 02     2
> 
> 02     3
> 
> 02     1
> 
> 03     2
> 
> 03     2
> 
> 03     2
> 
> 03     1
> 
> 03     1
> 
> 03     1
> 
> etc...
> 
> I would like to end up with a dataframe with one row per ID 
> where the value in the contract field would be the highest 
> value recorded for a single ID. As you can see above, the 
> number of IDs varies irregularly.  Given the above, the new 
> file would look like the following:
> 
> ID     Contract
> 
> 01     1
> 
> 02     3
> 
> 03     2
> 
> Thanks in advance for your suggestions.
> 
> Gregory L. Blevins The Market Solustions Group, Partner
> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
> 


------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments,...{{dropped}}




More information about the R-help mailing list