1

I really need your help and I'm sorry in advance for my english !

I have to add a counter variable to my dataframe. A first grouping is made with the ID and num_order variables. In this grouping my counter should number the rows as a rank but assign the same rank to similar second grouping (col1, col2, ok).

This is my dataframe :

df <- 
data.frame(id=c("A03","A03","A03","A03","A03","A03","A03","A03","A03","A03","A03","Z07","Z07","Z07"),
num_order=c("17","17","17","17","17","17","17","17","5","5","5","23","23","23"),
col1=c("aaa","aaa","bbb","ccc","ccc","ddd","eee","ccc","aaa","hhh","ccc","ddd","eee","eee"),
col2=c("aaa","aaa","bbb","ccc","ccc","ddd","eee","eee","aaa","hhh","ccc","ddd","eee","eee"),
ok=c("yes","yes","no","no","no","no","no","no","yes","no","no","no","no","no"),
counter=c(1,1,2,3,3,4,5,6,1,2,3,1,2,2))

The result I am looking for is in the counter column.

Thanks a lot for your help

zoe
  • 11
  • 2

0 Answers0