Transform a list (list) into a database (data.frame)

Asked

Viewed 45 times

2

I have the list below. I would like to turn it into a data.frame (or Tibble):

dados.lista <- list(id = 2287276L, uri = "https://dadosabertos.camara.leg.br/api/v2/proposicoes/2287276", 
    siglaTipo = "SBT", codTipo = 255L, numero = 1L, ano = 0L, 
    ementa = "", dataApresentacao = "2021-06-16T17:24", uriOrgaoNumerador = NULL, 
    statusProposicao = list(dataHora = "2021-06-16T17:24", sequencia = 1L, 
        siglaOrgao = "PLEN", uriOrgao = "https://dadosabertos.camara.leg.br/api/v2/orgaos/180", 
        uriUltimoRelator = NULL, regime = ".", descricaoTramitacao = "Apresentação de Proposição", 
        codTipoTramitacao = "100", descricaoSituacao = NULL, 
        codSituacao = NULL, despacho = "Apresentação do Substitutivo n. 1 PLEN, pelo Deputado Carlos Zarattini (PT-SP).", 
        url = "http://www.camara.gov.br/proposicoesWeb/prop_mostrarintegra?codteor=2029277", 
        ambito = "Regimental"), uriAutores = "https://dadosabertos.camara.leg.br/api/v2/proposicoes/2287276/autores", 
    descricaoTipo = "Substitutivo", ementaDetalhada = NULL, keywords = NULL, 
    uriPropPrincipal = NULL, uriPropAnterior = NULL, uriPropPosterior = NULL, 
    urlInteiroTeor = "http://www.camara.gov.br/proposicoesWeb/prop_mostrarintegra?codteor=2029277", 
    urnFinal = NULL, texto = NULL, justificativa = NULL)

I tried the following code, unsuccessfully:

library(tidyverse)
dados.lista %>% 
  map(unlist) %>% 
  as_tibble()

Someone could show me a way out. Grateful.

1 answer

3


Firstly, it is necessary to transform the null elements (NULL) of that list.

df_1 <- lapply(dados.lista, Filter, f = Negate(is.null))

Once done, aggregate the variables with rbind.fill. Thus:

library(plyr)

df_2 <- rbind.fill(lapply(df_1, as.data.frame))
  • perfect, Neves, thank you so much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.