Hello, I would like to add a counter column in a data frame based on a set of identical rows. To do this, I tested:
DF = data.table(x=c("a","a","a","b","c","d","e","f","f"), y=c(1,3,2,8,8,4,NA,NA,NA)) DF[ , Index := .GRP, by = c("y") ] DF However, the rows with NAs are considered to be identical. So, how can I obtain: x y Index 1: a 1 1 2: a 3 2 3: a 2 3 4: b 8 4 5: c 8 4 6: d 4 5 7: e NA 6 8: f NA 7 9: f NA 8 Instead of: x y Index 1: a 1 1 2: a 3 2 3: a 2 3 4: b 8 4 5: c 8 4 6: d 4 5 7: e NA 6 8: f NA 6 9: f NA 6 Thank you very much for your time. Have a nice day Marine [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.