# leave only 'setosa'
where(iris, Species == "setosa")
# leave only first five rows
where(iris, 1:5)
# infix version
# note that '%where%' have higher precendence than '=='
# so we need to put condition inside brackets
iris %where% (Species == "setosa")
iris %where% 1:5
# example of .n usage. Very artificial examples
set.seed(42)
train = iris %where% sample(.n, 100)
str(train)
set.seed(42)
test = iris %where% -sample(.n, 100)
str(test)
Run the code above in your browser using DataLab