[r] R: `which` statement with multiple conditions

I have a matrix which consists of 13 columns (called PCs). I want to make a new matrix including only the rows that have a value between 4 and 8 (called EUR). I tried using this statement:

EUR <- PCs[which(PCs$V13 < 9 && PCs$V13 > 3), ]

Which unfortunately doesn't work... (I only get one row out, while there are hundreds)

Anyone knows what's wrong with this command?

This question is related to r

The answer is


The && function is not vectorized. You need the & function:

EUR <- PCs[which(PCs$V13 < 9 & PCs$V13 > 3), ]