This should do what you want: set.seed(1) # cerating a vector with comments, in which d's will be counted comments<-character(25) for (i in 1:25) { comments[i] <- paste(sample(letters[1:10], 10, replace=T), collapse="") }
# creating a vector to cross -tabulate age <-sample(c("old", "young"), 25, replace=T) # find d's in comments, determine their frequencies, and crosstab table(sapply(gregexpr("d", comments), length), age) HTH, STG ______________________________________________ R-help@r-project.org mailing list 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.