Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

R - Filter rows by columns - column names contained in an other dataframe

$
0
0

An other basic question, but I can't seem to find a solution.

Take mtcars as an example. I would like to know the number of rows, where vs AND am are above 0.5. AND

df<- mtcars
x <- subset(mtcars, (vs > 0.5) & (am > 0.5))

OR

df<- mtcars
x <- subset(mtcars, (vs > 0.5) | (am > 0.5))

Easy so far.

Now I would like to vary exactly which column I want to use for filtering. And the column names I want are contained in an other dataframe. How can I do the filtering? How can I do it so that the column names are compared with OR or AND - that is all the column-row pairs are compared or either column-row pair.

df<- mtcars
colnames <- c("vs","am")
x <- subset(mtcars, mtcars[,colnames] > 0.5)

Does not give right answer... Thanks for help!


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>