Home Use Variables to Generalise a Paste query
Reply: 0

Use Variables to Generalise a Paste query

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?

share|improve this question
  • 1
    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

1 Answer 1

active oldest votes
up vote 0 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.34808 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO