Aparanji - 26 days ago 5x

R Question

I have a 4X5 matrix example:

`a = 1 2 3 4 5`

2 3 3 4 1

5 6 77 8 9

10 9 3 4 17

Here I want to know the row number where

`a[,3] == 3`

`a[,4] == 4`

I am suppose to get the answer as 1,2 and 4

How do I get it in r

Answer

use this

```
a = matrix(c(1,2,3,4,5,2,3,3,4,1,5,6,77,8,9,10,9,3,4,17), byrow = T, ncol = 5)
which(a[, 3] == 3 & a[ ,4] == 4)
```

[1] 1 2 4

Source (Stackoverflow)

Comments