pivot_longer( data, cols, #to select based on name use starts_with("pattern_"), names_to = "name", names_prefix = NULL, names_sep = NULL, names_pattern = NULL, names_ptypes = list(), names_transform = list(), names_repair = "check_unique", values_to = "value", values_drop_na = FALSE, values_ptypes = list(), values_transform = list(col1 = as.integer col2 = as.numeric), ) ### Deriving variables from complex column headers ### df %>% pivot_longer ( cols, names_to = c("var1", ".value"), names_sep = "_")
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter