raja shekara j
raja shekara j

Reputation: 1

How to assign unique rank number for duplicate values in R

I have a large data set like the below example, How to assign a unique rank number to duplicate or repeated values with a combination of more than one column condition. like rank to be assigned with reference to cluster & value column.

enter image description here

Example data table & required output:

required out put

Upvotes: -1

Views: 2068

Answers (1)

Dan Chaltiel
Dan Chaltiel

Reputation: 8484

I think this should do:

library(dplyr)
x=data.frame(id=c(1,1,2,3,4,4,5,6,7), value=c(10,10,10,20,20,20,20,20,30))
x %>% 
  arrange(id, value) %>%
  group_by(value) %>%
  mutate(rank=row_number(value))

Upvotes: 1

Related Questions