Home Use Variables to Generalise a Paste query

# Use Variables to Generalise a Paste query

user7643
1#
user7643 Published in September 21, 2018, 8:18 am

I have used this query to remove all items in my data set which are brought up in December 2017. I want to generalise this query by using variables instead of 'Dec' and '2017' as I will be firing this query every month.

q2_sql_1 <- subset(q2_sql_1,  ! paste(CAL_MONTH,YEAR,sep="_") %in% c('Dec_2017'))


The overall code is quite big, so it would be troublesome to find this line and edit every time. So, I have specified 2 variables at the beginning which I will edit every month.

MMM <- "Dec"
YYYY <- "2017"


How do I use these variables in the above query?

• q2_sql_1 <- subset(q2_sql_1, ! paste(CAL_MONTH,YEAR,sep="_") %in% paste0(MMM, "_", YYYY)) – lebatsnok Feb 13 at 8:03
• Worked as a charm. Thank You. – Aneesh Feb 13 at 8:32
• @lebatsnok can you post it as an answer ? – Moody_Mudskipper Feb 13 at 8:39