you can use rle
- Run Length Encoding
# Create the data.frame
group <- c("A","A","A","A","A","B","B","C","C","C")
replicate <- c(1,2,3,4,5,1,2,1,2,3)
x <- data.frame(group,replicate)
# using 'rle'
z <- rle(as.numeric(x$group))$lengths
x$max.per.group <- rep(z, z)
x