user3358686
user3358686

Reputation: 921

index giving rows of the matrix

I have a matrix named song with a row for each word occurring in five songs lyrics and a column of counts for each song. I would like to create an index giving which rows of the matrix correspond to a word in x

x = c("is", "the", "I", "you")

I did

song[is.element(song, x),]

but this gives me another matrix which the value is true.

Upvotes: 0

Views: 51

Answers (1)

Jealie
Jealie

Reputation: 6267

I would try:

which(song[,1] %in% x)

Does this help?

Upvotes: 1

Related Questions