Using ddply
library(plyr)
ddply(mydata, .(v), mutate, counts = length(v))
# v counts
#1 1 2
#2 1 2
#3 2 3
#4 2 3
#5 2 3
#6 3 1
Or lapply
do.call(rbind, lapply(split(mydata, mydata$v),
function(x){ x$counts = length(x$v); x}))
# v counts
#1.1 1 2
#1.2 1 2
#2.3 2 3
#2.4 2 3
#2.5 2 3
#3 3 1