Reputation: 11
I am working with the MarketMatching package in R.
MarketMatching gives a list of 5 comparison Markets for my target Market. However, I want to remove specific markets from this list.
The MarketMatching object looks like this in R studio: Screenshot
I tried it like this (where 'mm' is the object described above), 'BestControl' is a column with values "PL", "FI", "NG", "GH", "RU". So I want to delete GH and NG from that list.
active_campaigns <- c("GH", "NG")
mm$BestMatches <- mm$BestMatches[!(BestControl %in% active_campaigns),]
Out:
Error in BestControl %in% active_campaigns : object 'BestControl' not found
In other words: How can I access a column of a dataframe that is embedded in a list to drop rows there?
Upvotes: 1
Views: 450
Reputation: 1449
You can subset the rows you want (i.e. no character from BestControl within active_campaigns).
# 1- Create a function for testing boolean "not within"
'%!in%' <- function(x,y)!('%in%'(x,y))
# 2- Subset the string not within active_campaigns
mmSubset <- subset(mm$BestMatches, BestControl %!in% active_campaigns)
Upvotes: 1