A <-data.frame(c('A','A','B','C','C','A','C','B','A'),c(3,1,7,6,5,4,2,9,8))
names(A) <-c('name','number')
A <- A[order(A$name, A$number),]
A <- A[!duplicated(A$name),]
library(dplyr)
A <- data.frame(name = c('A', 'A', 'B', 'C', 'C', 'A', 'C', 'B', 'A'),
number = c(1:9))
> A
name number
1 A 1
2 A 2
3 B 3
4 C 4
5 C 5
6 A 6
7 C 7
8 B 8
9 A 9
B <- A %>%
group_by(name) %>%
summarise(number = min(number))
> B
Source: local data frame [3 x 2]
name number
(fctr) (int)
1 A 1
2 B 3
3 C 4
A <-data.frame(c('A','A','B','C','C','A','C','B','A'),c(1:9))
names(A) <-c('name','number')
install.packages('sqldf')
library(sqldf)
> A
name number
1 A 1
2 A 2
3 B 3
4 C 4
5 C 5
6 A 6
7 C 7
8 B 8
9 A 9
> sqldf("SELECT a1.name,a1.number from A a1 where a1.number=(SELECT min(a2.number) from A a2 where a2.name=a1.name)")
name number
1 A 1
2 B 3
3 C 4
>