nm1 <- unique(s$flavor) for(i in seq_along(unique(s$flavor))){ tmp <- s$age[s$flavor == nm1[i] ] v1[i] <-paste("mean =", mean(tmp), "sd =", sd(tmp)) }