[R] A file manipulation question
Andrew Robinson
andrewr at uidaho.edu
Thu Mar 4 04:53:08 CET 2004
How about something like ... (if your data frame is called the.data)
summarized <- as.data.frame(levels(the.data$ID))
names(summarized) <- "ID"
summarized$Contract <- as.numeric(tapply(the.data$Contract, the.data$ID, max))
Andrew
On Wednesday 03 March 2004 19:19, Greg Blevins wrote:
> 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
--
Andrew Robinson Ph: 208 885 7115
Department of Forest Resources Fa: 208 885 6226
University of Idaho E : andrewr at uidaho.edu
PO Box 441133 W : http://www.uidaho.edu/~andrewr
Moscow ID 83843 Or: http://www.biometrics.uidaho.edu
No statement above necessarily represents my employer's opinion.
More information about the R-help
mailing list