I have a dataframe that I'm trying to query using the %in% operator and the contents of another dataframe, which has worked perfectly well.
However, what I'm trying to do now, is to also query where the contents of my dataframe are similar to the second dataframe.
Is there a way to combine an %in%
and %like%
operator?
I've pasted my code using the %in% operator below, which is working as expected:
sessionData <- as_data_frame(sessionData[sessionData$pagePath %in% pageUrls$page_url,])
When using both the %in%
and %like%
, it only returns data from the first row in the lookup dataframe - is there a better way to query this?
Edit: As requested, I've pasted some reproducible data example data below, as well as a further information on expected outputs:
df <- data.frame("url" = c('url1','url1-variation1','url1-variation2','url2','url2-variation1','url2-variation2','url3','url3-variation1','url3-variation2'), stringsAsFactors = FALSE)
df_lookup <- data.frame("url" = c('url1','url2','url3'), stringsAsFactors = FALSE)
df_out <- as_data_frame(df[df$url %in% df_lookup$url,])
As you can see, when using the %in%
operator, it only returns exact matches. What I'm attempting to do, is also return the variations, using a %like%
operator, or something similar.