I have a data frame and tried to select only the observations I'm interested in by this:
data[data["Var1"]>10]
Unfortunately, this command destroys the data.frame
structure and returns a long vector
.
What I want to get is the data.frame
shortened by the observations that don't match my criteria.
Another method utilizing the dplyr package:
library(dplyr)
df <- mtcars %>%
filter(mpg > 25)
Without the chain (%>%) operator:
library(dplyr)
df <- filter(mtcars, mpg > 25)
Source: Stackoverflow.com