Let's call your matrix df
f you want to know how many rows there are in your matrix: nrow(df)
If you want to know the index for an specific value: which([logical]) for example which(df$col1 ==2)