
Last chance! 50% off unlimited learning
Sale ends in
For the data frame cond
will be evaluated in the data.frame's context.
So columns can be referred as variables in the expression (see the examples).
If data
is list then where
will be applied to each element of
the list. For other types (vector/matrix) there is no non-standard
evaluation. There is a special constant .N
which equals to number of
rows in data
for usage in cond
expression.
where(data, cond)
data.frame/matrix/vector/list which contains just selected rows.
data.frame/matrix/vector/list to be subsetted
logical or numeric expression indicating elements or rows to
keep: missing values (NA) are taken as FALSE. If data
is data.frame
then cond
will be evaluated in the scope of the data
.
# leave only 'setosa'
rows(iris, Species == "setosa")
# leave only first five rows
rows(iris, 1:5)
# example of .N usage.
set.seed(42)
train = rows(iris, sample(.N, 100))
str(train)
set.seed(42)
test = rows(iris, -sample(.N, 100))
str(test)
Run the code above in your browser using DataLab