Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

R read a list of items, that can be passed in filter

Hello looking for help:

Say I have a list of the items

my.list <- read.csv("~/R/Work Stuff/Data/Read.csv")

After read.csv –
Item
1 ItemA
2 ItemB
3 ItemC

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Now I want to create a new vector MPP.Item which is essentially my list of items which I want to use as a filter condition to filter other data set.

MPP.Item=c(my.list)

MPP %>% filter(Item %in% MPP.Item)

However, it is not working. If I am manually creating it as a vector say:

my.list2 <- c("ItemA", "ItemB", "ItemC")

Works fine

Thanks for your advises

>Solution :

my.list is a dataframe, extract the vector from it.

library(dplyr)

MPP.Item = my.list$Item

MPP %>% filter(Item %in% MPP.Item)

#Without using additional variable `MPP.Item`. 
#MPP %>% filter(Item %in% my.list$Item)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading