library(dplyr)
df %>% # df is the dataframe with data
group_by(year) %>% # "year" is the variable indicates the year information of observations
arrange(variable) # "variable" is the variable you want to arrange rows by order according to
在R语言中,这种问题的解决就是这么简单直接,因为运用R的,是统计学家,是数据分析师,不是程序员。如果连这么一个简单的、一次性的数据探索的操作都要牵扯那么多精力的话,你的思维早就被打断了无数次了。