我会这样做的:
library(tidyr)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
structure(list(col = c("A", "B", "C"), `2000-01-01` = c(86L,
43L, 73L), `2000-01-02` = c(99L, 77L, 12L)), class = "data.frame", row.names = c(NA,
-3L)
) %>%
pivot_longer(-col, names_to = 'date', values_to = 'count') %>%
arrange(date, col)
#> # A tibble: 6 Ã 3
#> col date count
#> <chr> <chr> <int>
#> 1 A 2000-01-01 86
#> 2 B 2000-01-01 43
#> 3 C 2000-01-01 73
#> 4 A 2000-01-02 99
#> 5 B 2000-01-02 77
#> 6 C 2000-01-02 12
创建于2022-12-09
reprex v2.0.2