I have a function fetchWeather(city,month1,year1,...)
that takes an unlimited combination of month/year inputs and spits out weather data for those periods.
I'd like to make it a little more compact by doing some combinations by shorthand. so for example, rather than
fetchWeather(Boston,4,2015,5,2015,6,2015,7,2015,8,2015,9,2015,10,2015)
I'd like to do
jv15<- c(4,2015,5,2015,6,2015,7,2015,8,2015,9,2015,10,2015)
and then call
fetchWeather(Boston,jv15)
but I can't get this to work.
I'm pretty new to R and I imagine that this is a pretty easy solve but I can't seem to figure it out. any help is appreciated.
Your error might be that boston is not in quotes, but assuming that Boston is truly a variable...
You can use 'do.call'
Takes a function and a list and calls a function with that list as arguments.
So first you'd want to prepend Boston onto your list and then do.call.
out.weather <- do.call(fetchWeather, c(Boston,jv15))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With