-1

I'm trying to import data from Estonian national database through r into powerbi, but sometimes the data gives me an error which i don't know how to resolve.

I have tried using different data from the same database and with some it works fine, but others throw an error.

I have this code:

library(stringr)
library('rsdmx')
data = readSDMX('http://andmebaas.stat.ee/restsdmx/sdmx.ashx/GetData/LET171/1+2+3+4+5+6+7+8+9+10+11+12+13+14.1+2+3/all?startTime=2010&endTime=2016')
DF = as.data.frame(data)
dsd = readSDMX("http://andmebaas.stat.ee/restsdmx/sdmx.ashx/GetDataStructure/LET171")
cls=slot(dsd, "codelists")
codelists <- sapply(slot(cls, "codelists"), function(x) slot(x, "id"))
for(i in codelists){
  kood <- str_sub(i, start= 10)
  if(kood!="OBS_STATUS"){
    assign(kood, as.data.frame(slot(dsd, "codelists"), codelistId = i))
  }
}

It works fine with some data, for example using these links

Data http://andmebaas.stat.ee/restsdmx/sdmx.ashx/GetData/RV021/1+2+3.1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+31+32+33+34+20+21/all?startTime=1919&endTime=2019

dsd http://andmebaas.stat.ee/restsdmx/sdmx.ashx/GetDataStructure/RV021

The code is supposed to import the data into powerbi and create tables with data and identifiers, but with the links currently in the code it throws the following error

Error in colSums(is.na(codes)) : 'x' must be an array of at least two dimensions In addition: Warning message: In is.na(codes) : is.na() applied to non-(list or vector) of type 'NULL'

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Raul
  • 1
  • 1

1 Answers1

0

Looks like codes is a vector and that the colSums() function needs a matrix as argument. I did not go through all your example, but if you want to convert a vector into a matrix, you could do it with

codes <- as.matrix(codes, nrow=your_nrow, ncol=your_ncol)

where you can only give one of nrow or ncol.

J.P. Le Cavalier
  • 1,315
  • 7
  • 16