(1) For select data (subset), I highly recommend subset
function from plyr
package written by Hadley Wickhm, it is cleaner and easy to use:
library(plyr)
subset(data, x > 4 | y > 4)
UPDATE:
There is a newer version of plyr
called dplyr
(here) which is also from Hadley, but supposedly way faster and easier to use. If you have ever seen operatior like %.%
or %>%
, you know they are chaining the operations using dplyr
.
result <- data %>%
filter(x>4 | y>4) #NOTE filter(condition1, condition2..) for AND operators.
(2) There indeed exist some differences between |
and ||
:
You can look at the help manual by doing this: ?'|'
The shorter form performs elementwise comparisons in much the same way as arithmetic operators. The longer form evaluates left to right examining only the first element of each vector. Evaluation proceeds only until the result is determined. The longer form is appropriate for programming control-flow and typically preferred in if clauses.
> c(1,1,0) | c(0,0,0)
[1] TRUE TRUE FALSE
> c(1,1,0) || c(0,0,0)
[1] TRUE
Per your question, what you did is basically data[TRUE]
, which ...will return the complete dataframe.