如何在R中分解数据

时间:2018-10-31 14:19:41

标签: r decomposition

有人对如何分解r中的数据集有建议吗?另外,第一列以字符形式出现,但是当我运行ggplot时,它被正确分析为日期数据。我还需要将其转换为日期吗?如果可以,怎么办?

please click here for data set

1 个答案:

答案 0 :(得分:0)

好吧,我正在努力摆脱自己的想象力,摆脱分解作曲家的黑暗视线...但是,如果 season 表示 year ,而 decomposition 表示使用作词者{em> {em> },使用your data,可以用以下方式完成:

library(tidyverse)
library(lubridate)
library(ggthemes)

read_csv("test2.csv") %>%     
  mutate(date = ymd(paste(month,"-01", sep="")), month = NULL) %>%
  mutate(season = cut(date, "year")) %>% 
  group_by(season, composer) %>%
  summarise(popularity = mean(popularity)) %>%
  ggplot(aes(x = year(season), y = popularity, group = composer, colour = composer)) +
      geom_line(alpha = 0.75) +
      ggthemes::scale_colour_gdocs(name = "Composer:") + # comment out this line
      labs(x = "Season", y = "Popularity") +
      ggthemes::theme_few()                              # comment out this line

trendy composers