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?
Multiple Conditions To join two or more conditions into a single if statement, use logical operators viz. && (and), || (or) and ! (not). && (and) expression is True, if all the conditions are true.
Nested If Statement It is used to check the multiple conditions. This statement is like executing an if statement inside an else statement.
Multiple conditions can also be combined using which() method in R. The which() function in R returns the position of the value which satisfies the given condition. The %in% operator is used to check a value in the vector specified.
The SQL AND & OR operators are used to combine multiple conditions to narrow data in an SQL statement. These two operators are called as the conjunctive operators. These operators provide a means to make multiple comparisons with different operators in the same SQL statement.
The &&
function is not vectorized. You need the &
function:
EUR <- PCs[which(PCs$V13 < 9 & PCs$V13 > 3), ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With