r - How to efficiently filter a data frame? -


i have data frame , tried select observations i'm interested in this:

data[data["var1"]>10] 

unfortunately, command destroys data.frame structure , returns long vector.

what want data.frame shortened observations don't match criteria.

you missing comma in statement.

try this:

data[data[, "var1"]>10, ] 

or:

data[data$var1>10, ] 

or:

subset(data, var1>10) 

as example, try on built-in dataset, mtcars

data(mtcars)  mtcars[mtcars[, "mpg"]>25, ]                  mpg cyl  disp  hp drat    wt  qsec vs gear carb fiat 128       32.4   4  78.7  66 4.08 2.200 19.47  1  1    4    1 honda civic    30.4   4  75.7  52 4.93 1.615 18.52  1  1    4    2 toyota corolla 33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1 fiat x1-9      27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1 porsche 914-2  26.0   4 120.3  91 4.43 2.140 16.70  0  1    5    2 lotus europa   30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2   mtcars[mtcars$mpg>25, ]                  mpg cyl  disp  hp drat    wt  qsec vs gear carb fiat 128       32.4   4  78.7  66 4.08 2.200 19.47  1  1    4    1 honda civic    30.4   4  75.7  52 4.93 1.615 18.52  1  1    4    2 toyota corolla 33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1 fiat x1-9      27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1 porsche 914-2  26.0   4 120.3  91 4.43 2.140 16.70  0  1    5    2 lotus europa   30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2  subset(mtcars, mpg>25)                  mpg cyl  disp  hp drat    wt  qsec vs gear carb fiat 128       32.4   4  78.7  66 4.08 2.200 19.47  1  1    4    1 honda civic    30.4   4  75.7  52 4.93 1.615 18.52  1  1    4    2 toyota corolla 33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1 fiat x1-9      27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1 porsche 914-2  26.0   4 120.3  91 4.43 2.140 16.70  0  1    5    2 lotus europa   30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -