-5

I have a data frame in R with columns "name" and "length". The "name" is not unique and the same "name" repeats several times in the data frame. But I wanted to keep only one row with the largest "length" for each "name". Which function in R can I use to do this?

ekad
  • 14,436
  • 26
  • 44
  • 46
Runner
  • 365
  • 1
  • 5
  • 21
  • 2
    Your question was "clear". I downvoted because it displays almost no effort on your part. No reproducible example, no code showing what you've tried so far. – joran Mar 02 '15 at 03:14
  • 3
    Try something like this: http://stackoverflow.com/questions/21982987/mean-per-group-in-a-data-frame but with max() instead of mean(). Lots of approaches possible. – Sam Firke Mar 02 '15 at 03:26

1 Answers1

1

I created a sample data. Hope this is what you need

df <- data.frame(names=c('A','A','A','A','B','B','B','C','C','C','C','C'),Length=c(1:12))

library(plyr)
 df2<- ddply(df, "names", subset, Length==max(Length))
jbest
  • 640
  • 1
  • 10
  • 28