r - Unlisting columns by groups -
i have dataframe in following format:
id | name | logs ---+--------------------+----------------------------------------- 84 | "zibaroo" | "c47931038" 12 | "fabien kelyarsky" | c("c47331040", "b19412225", "b18511449") 96 | "mitra lutsko" | c("f19712226", "a18311450") 34 | "paulsandoz" | "a47431044" 65 | "beamvision" | "d47531045"
as see column "logs" includes vectors of strings in each cell.
is there efficient way convert data frame long format (one observation per row) without intermediary step of separating "logs" several columns?
this important because dataset large , number of logs per person seems arbitrary.
in other words, need following:
id | name | log ---+--------------------+------------ 84 | "zibaroo" | "c47931038" 12 | "fabien kelyarsky" | "c47331040" 12 | "fabien kelyarsky" | "b19412225" 12 | "fabien kelyarsky" | "b18511449" 96 | "mitra lutsko" | "f19712226" 96 | "mitra lutsko" | "a18311450" 34 | "paulsandoz" | "a47431044" 65 | "beamvision" | "d47531045"
here dput
of section of real dataframe:
structure(list(id = 148:157, name = c("avihil1", "niarfe", "doug henderson", "nick tan", "madisp", "woodbusy", "kevinhcross", "cylol", "andrewarrow", "gstavrev"), logs = list("z47331572", "z47031573", c("f47531574", "b195945", "d186871", "s192939", "s182865", "g19539045"), c("a47231575", "a190933", "c181859"), "f47431576", c("b47231577", "d193936", "q184862"), "y47331579", c("a47531580", "z195944", "b185870"), "n47731581", "e47231582")), .names = c("id", "name", "logs" ), row.names = 149:158, class = "data.frame")
this perfect case tidyr:
library(tidyr) library(dplyr) dat %>% unnest(logs)
Comments
Post a Comment