Preserve order of columns when going from wide to long format
问题 I'm trying to preserve the order of columns when I gather them from wide to long format. The problem I'm having is after I gather and summarize the order is lost. The number of columns is huge so I don't want to manually type the order. Here's an example: library(tidyr) library(dplyr) N <- 4 df <- data.frame(sample = c(1,1,2,2), y1.1 = rnorm(N), y2.1 = rnorm(N), y10.1 = rnorm(N)) > df sample y1.1 y2.1 y10.1 1 1 1.040938 0.8851727 -0.3617224 2 1 1.175879 1.0009824 -1.1352406 3 2 -1.501832 0