dimanche 4 février 2018

Pass variable as condition for if-statement or filter, in r

I'm curious to know how I might achieve something like the following in R.

I hope this psodu-code illustrates the concept.

g <- 10
condition <- "g > 9"
if(condition) print("This works")

Specifically, does anyone know if it is possible to do something like this with the dplyr filter function? (Again, psudo-code):

df <- data.frame(one = 1:5, two = 6:10, three = 11:15)
condition <- "two == 7 | one == 1"
filter(df, condition)

Aucun commentaire:

Enregistrer un commentaire