Leilei Zhou
Leilei Zhou

Reputation: 3

How to subset a dataframe based on a list of value in r

I have a big dataframe and a list of value (character). I want to subset the dataframe based on one column which contains value in the list. What should I do?

Thanks Leilei

Upvotes: 0

Views: 146

Answers (1)

tlhenvironment
tlhenvironment

Reputation: 349

I assume you want something like this.. Please make a reproducable example next time ://

data.frame(letters = c("a", "b", "c", "d"), value = 1:4) -> df
list("a", "y", "b", "x") -> subset_list

df[df$letters %in% subset_list,] -> df_subset

Upvotes: 1

Related Questions