How to copy grouped rows into column by dplyr/tidyverse in R?
问题 I am trying to copy sets of rows into columns using dplyr. Following is my data frame. df <- data.frame( hid=c(1,1,1,1,2,2,2,2,2,3,3,3,3), mid=c(1,2,3,4,1,2,3,4,5,1,2,3,4), tmid=c("010","01010","010","01020", "010","0120","010","010","020", "010","01010","010","01020"), thid=c("010","02020","010","02020", "000","0120","010","010","010", "010","02020","010","02020"), ) It is printed in the following format: > df hid mid tmid thid 1 1 1 010 010 2 1 2 01010 02020 3 1 3 010 010 4 1 4 01020 02020