Skip to content
Prev 319091 / 398503 Next

Word Frequency for each row

Hello,

I'm not sure I understand, but see if the following is an example of 
counting occurences of a word in each row.


set.seed(1855)
x <- matrix(sample(LETTERS[1:5], 400, replace = TRUE), ncol = 4)
word <- "A"
where <- apply(x, 1, function(.x) grep(word, .x))
sapply(where, length)  # count them


Hope this helps,

Rui Barradas

Em 08-03-2013 16:04, Sudip Chatterjee escreveu: