Andres Mora
Andres Mora

Reputation: 1106

how to convert list to dataframe

my data

df = list(personaId = 0, pacienteId = 1408849, sexoId = 0, departamentoResidencia = "CUNDINAMARCA", 
    municipioResidencia = "ANAPOIMA", tipoIdentificacion = "Cédula de ciudadanía", 
    numeroIdentificacion = "12345", primerNombre = "ivone", segundoNombre = "", 
    primerApellido = "moya", segundoApellido = NULL, fechaNacimiento = "1924-11-17T00:00:00")

Im trying to convert this to a dataframe with no luck. I know im missing something simple.

My desired output

personaId pacienteId sexoId departamentoResidencia municipioResidencia tipoIdentificacion      numeroIdentificacion primerNombre segundoNombre primerApellido segundoApellido fechaNacimiento 
0         1408849       0   CUNDINAMARCA           ANAPOIMA            Cédula de ciudadanía    12345                ivone                      moya           NULL            1924-11-17T00:00:00

Upvotes: 0

Views: 75

Answers (2)

akrun
akrun

Reputation: 886938

We can use

library(dplyr)
bind_cols(df) 

Upvotes: 0

Ronak Shah
Ronak Shah

Reputation: 388797

If you want to maintain the column segundoApellido which has NULL you may need to change it to NA and then a simple data.frame call should work.

df[sapply(df, is.null)] <- NA
data.frame(df)

Upvotes: 3

Related Questions