Comments (4)
Note that to do this in a tidy way the structure of the return value would have to change from:
# A tibble: 846 x 2
date UNRATE
<date> <dbl>
1 1948-01-01 3.4
2 1948-02-01 3.8
3 1948-03-01 4
4 1948-04-01 3.9
5 1948-05-01 3.5
6 1948-06-01 3.6
7 1948-07-01 3.6
8 1948-08-01 3.9
9 1948-09-01 3.8
10 1948-10-01 3.7
# ... with 836 more rows
to
# A tibble: 846 x 3
date key value
<date> <chr> <dbl>
1 1948-01-01 UNRATE 3.4
2 1948-02-01 UNRATE 3.8
3 1948-03-01 UNRATE 4
4 1948-04-01 UNRATE 3.9
5 1948-05-01 UNRATE 3.5
6 1948-06-01 UNRATE 3.6
7 1948-07-01 UNRATE 3.6
8 1948-08-01 UNRATE 3.9
9 1948-09-01 UNRATE 3.8
10 1948-10-01 UNRATE 3.7
# ... with 836 more rows
so we can stack series.
I'd be okay with just doing it for fredr_series_observations()
. It makes the most sense there and is easy to understand how you'd add multiple series together. The approach could be:
fredr_series_observations()
changes tofredr_series_observations_single()
(it would not be exported)- The inners of
fredr_series_observations_single()
changes a little so that it returns in the format like above (an easy change from the looks of it) - The "new"
fredr_series_observations()
function does anlapply()
across theseries_id
values, calling the single function each time. Then you dodo.call(rbind, lapply_result_list)
to get your final product.
Ideally I'd use purrr::map_dfr()
but that implicitly introduces a purrr
AND a dplyr
dependency.
from fredr.
Upon further reflection, I think this is a little beyond the scope of something this package should support.
With the advent of purrr
, I'm no longer sure I see the pressing need to vectorize single function I write. We could include the purrr::map_dfr()
approach as a recipe in the vignettes. Did you have a use case in which this approach is too cumbersome?
from fredr.
I was just going with the general R theory that things are vectorised. But I totally see your point. It's nice with purrr too because pmap()
gives us iteration over both the series_id and, say, the observation_start for free, where otherwise we'd have to do a lot of work to vectorize every arg.
That being said, I do think we may want to change the structure of the return value so they stack nicely. Maybe have a date
, series
and value
column. Do you agree?
from fredr.
Yes I see what you're saying. date
, series_id
and value
as columns is a good compromise for now.
from fredr.
Related Issues (20)
- Unable to Install (Broken Dependency?) HOT 2
- Support for FRED Maps HOT 3
- Option to select Seasonally Adjusted Observation HOT 1
- upper bound too low for limit in fredr_category_series() HOT 3
- Pagination HOT 1
- Encoding error with fredr_series_observations HOT 11
- Better test environment for API requests HOT 3
- CRAN issues HOT 25
- Removed from CRAN? HOT 2
- Fredr can't return a legit series_id HOT 3
- Getting fredr back on CRAN HOT 24
- Release fredr 2.0.0
- way to traverse category trees? HOT 4
- This likely isn't an issue with your code, but something to be wary of HOT 3
- Trouble downloading multiple FRED series HOT 5
- fredr() and parameter vintage_dates HOT 5
- M2 not FedFunds
- Release fredr 2.1.0 HOT 1
- fredr appears to be completely broken on my R setup HOT 6
- Capture multiple series simultaneously? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fredr.