Home Use Variables to Generalise a Paste query
Reply: 1

Use Variables to Generalise a Paste query

Aneesh
1#
Aneesh Published in 2018-02-13 08:01:05Z

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?

Aneesh
2#
Aneesh Reply to 2018-02-13 10:23:57Z

As answered by @lebatsnok

q2_sql_1 <- subset(q2_sql_1, ! paste(CAL_MONTH,YEAR,sep="_") %in% paste0(MMM, "_", YYYY))
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO