Re: [R] subsetting a data.frame

From: jim holtman <jholtman_at_gmail.com>
Date: Wed, 10 Oct 2007 08:40:19 -0400

Is this what you want?

> x <- read.table(textConnection("Score Name

+ 88           000019_0070
+ 88           000019_0070
+ 87           000019_0070
+ 79           002127_0658
+ 79           002127_0658
+ 77           002127_0658"), header=TRUE)

> # return best scores
> best <- by(x, x$Name, function(.nam){
+ .nam[which(.nam$Score == max(.nam$Score)),] + })
> do.call('rbind', best)

              Score Name

000019_0070.1    88 000019_0070
000019_0070.2    88 000019_0070
002127_0658.4    79 002127_0658
002127_0658.5    79 002127_0658

>

On 10/10/07, Joćo Fadista <Joao.Fadista_at_agrsci.dk> wrote:
> Dear all,
>
> I would like to be able to subset a data.frame in a special way. I will put here an example:
>
> Score Name
> 88 000019_0070
> 88 000019_0070
> 87 000019_0070
> 79 002127_0658
> 79 002127_0658
> 77 002127_0658
>
> So, for the above example I would like to have a new data.frame that has only the best "Score" for each "Name":
>
> Score Name
> 88 000019_0070
> 88 000019_0070
> 79 002127_0658
> 79 002127_0658
>
>
>
> Thanks in advance.
> Best regards,
> Joćo Fadista
>
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 10 Oct 2007 - 13:11:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 10 Oct 2007 - 16:35:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.