宽表变长表 - 图1

    1. ## Example 1:
    2. stocks = data.frame(
    3. time = as.Date('2009-01-01') + 0:9,
    4. X = rnorm(10, 0, 1),
    5. Y = rnorm(10, 0, 2),
    6. Z = rnorm(10, 0, 4)
    7. )
    8. stocks
    9. stocks %>%
    10. longer_dt(time)
    11. stocks %>%
    12. longer_dt("ti")
    13. # Example 2:
    14. library(tidyr)
    15. billboard %>%
    16. longer_dt(
    17. -"wk",
    18. name = "week",
    19. value = "rank",
    20. na.rm = TRUE
    21. )
    22. # or use:
    23. billboard %>%
    24. longer_dt(
    25. artist,track,date.entered,
    26. name = "week",
    27. value = "rank",
    28. na.rm = TRUE
    29. )
    30. # or use:
    31. billboard %>%
    32. longer_dt(
    33. 1:3,
    34. name = "week",
    35. value = "rank",
    36. na.rm = TRUE
    37. )