Select Data Frame Rows based on Values in Vector in R | element, filter [dplyr] & setDT [data.table]

preview_player
Показать описание
R code of this video:

x2 = letters[1:10])
data # Return example data

vec <- c(1, 7, 10) # Create example vector
vec # Return example vector

data[data$x1 %in% vec, ] # Applying %in%-operator

library("dplyr")

filter(data, x1 %in% vec) # Applying filter function

setDT(data, key = "x1")[J(vec)] # Applying setDT function

Follow me on Social Media:
Рекомендации по теме
Комментарии
Автор

I am trying to learn corresponding dplyr methods in data.table. This is a great video in that regard. I did not know "J" function existed. This channel is my reference channel for all things R.

dangunwangum
Автор

If we have gender column (male, female) in dataframe.
How to extract female rows from the dataframe

arthygunam
Автор

Thank you for the video. Is there a way to select rows by row number/position?

ashsun
join shbcf.ru