temospena / Rnotebook

a compilation of R chunks
http://web.tecnico.ulisboa.pt/~rosamfelix/r/COMPILACAO.html
1 stars 0 forks source link

add pivot_wide #16

Open temospena opened 4 years ago

temospena commented 4 years ago

dar o exemplo dos modos de transporte por município

TRIPSmodemunicipio = TRIPSmode %>% pivot_wider(id_cols = c(1,2), names_from = modo, values_from = viagens)
#cols 1 e 2= origem e destino
TRIPSmodemunicipio[is.na(TRIPSmodemunicipio)] = 0
temospena commented 3 years ago

e também pivot_longer, para por exemplo transformar matrizes em long_format

temospena commented 3 years ago

e em matrix de viagens, com o stplarn

TRIPSfreglx_matrix <- stplanr::od_to_odmatrix(TRIPSfreglxtodas_long[3:5]) #O, D, count
TRIPSfreglx_matrix[is.na(TRIPSfreglx_matrix)] = 0