# Querying only monthly series

**URL:** <https://dbnomics.discourse.group/t/querying-only-monthly-series/615>\
**Category:** Community\
**Created:** [July 31, 2022, 3:01pm UTC](https://dbnomics.discourse.group/t/querying-only-monthly-series/615 "2022-07-31T15:01:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![toast](https://avatars.discourse-cdn.com/v4/letter/t/6f9a4e/32.png) [@toast](https://dbnomics.discourse.group/u/toast)\
**Post date:** [July 31, 2022, 3:01pm UTC](https://dbnomics.discourse.group/t/querying-only-monthly-series/615/1 "2022-07-31T15:01:23Z")

</div>

Is there a simple way to use python or R to walk through all providers and get only monthly series?

If possible I’m capable of writing the code and can share, but would like a general yay or neigh before investing time.

Thanks!

---

<div class="post-metadata">

**Author:** ![s915](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@s915](https://dbnomics.discourse.group/u/s915)\
**Post date:** [September 9, 2022, 9:19pm UTC](https://dbnomics.discourse.group/t/querying-only-monthly-series/615/2 "2022-09-09T21:19:22Z")

</div>

Hi @toast,

There is a way with **R** to go through all providers and their datasets, and find those that have monthly series.  
I just warn you that it takes some time (~1-2h) to download all “dimensions” of the datasets.

At the end, you’ll have a `data.table` with two columns:

- _provider_: names of providers with at least one dataset with a dimension “frequency” (or freq or Freq…) that contains a frequency “M”.
- _dataset_: names of datasets with monthly series.

```auto
library(data.table)
library(rdbnomics)

options(rdbnomics.progress_bar_datasets = TRUE)
options(rdbnomics.progress_bar_dimensions = TRUE)

# function
sapply_no_null <- function(l, fun) {
  l <- sapply(
    simplify = FALSE,
    l,
    fun
  )
  l <- Filter(Negate(is.null), l)
  if (length(l) > 0) {
    l
  } else {
    NULL
  }
}

# ~1-2h to download and ~1.5Go
dimensions <- rdb_dimensions()

all <- sapply_no_null(
  dimensions,
  function(x) {
    sapply_no_null(
      x,
      function(y) {
        nm <- tolower(names(y))
        if (sum(grepl("^freq", nm)) > 0) {
          z <- y[grep("^freq", names(y), ignore.case = TRUE)]
          sapply_no_null(
            z,
            function(u) {
              if ("M" %in% u[[1]]) {
                u
              } else {
                NULL
              }
            }
          )
        } else {
          NULL
        }
      }
    )
  }
)

provider_dataset <- lapply(all, function(x) { data.table(dataset = names(x)) })
provider_dataset <- rbindlist(provider_dataset, idcol = "provider")
#> provider dataset
#> 1: ACOSS ECONOMIC_BAROMETER
#> 2: AIH GGO_IVORY_COAST
#> 3: AIH GGO_NIGERIA
#> 4: AIH GGO_SENEGAL
#> 5: BCB bop
#> ---                            
#> 4335: WTO ITS_MTP_MMPM
#> 4336: WTO ITS_MTP_MXP
#> 4337: WTO ITS_MTP_MXPM
#> 4338: WTO ITS_MTV_MM
#> 4339: WTO ITS_MTV_MX

# Check
dimensions[["ACOSS"]][["ECONOMIC_BAROMETER"]][["freq"]]
#> freq Frequency
#> 1: M Monthly
#> 2: Q Quarterly

```

Best.

---

<div class="post-metadata">

**Author:** ![cbenz](https://yyz2.discourse-cdn.com/free1/user_avatar/dbnomics.discourse.group/cbenz/32/33_2.png) [@cbenz](https://dbnomics.discourse.group/u/cbenz)\
**Post date:** [September 12, 2022, 8:58am UTC](https://dbnomics.discourse.group/t/querying-only-monthly-series/615/3 "2022-09-12T08:58:33Z")

</div>

Indeed, there is no way to query the whole DBnomics data, and you must iterate like @s915 explained.
