Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R_R_Grouping - Fatal编程技术网

在R

在R,r,grouping,R,Grouping,截至2013年,我有这种格式的数据。大约125年的数据 Season HomeGoals AwayGoals HomeWins AwayWins Draws 1888 350 236 78 32 22 1889 395 216 74 35 23 1890 357

截至2013年,我有这种格式的数据。大约125年的数据

    Season  HomeGoals   AwayGoals   HomeWins    AwayWins    Draws
    1888    350            236        78          32          22
    1889    395            216        74          35          23
    1890    357            197        82          34          16
我想把这些年分为10年一组,其中不同的列,如HomeGoals和其他列被添加到一个桶中。 我尝试了R中可用的剪切函数,但它不起作用

demoCut <- cut(df_season$Season,breaks = 10)
demoCut变量显示奇数值,如1.89e+0.5


我如何计算这些年数?

你的年数是数字吗

years <- as.numeric(c("1888", "1889", "1890", "1900"))

cut <- cut(years, breaks = 2)

假设您的年份存储在标有year的dataframe列中。您的数据帧是df,您需要一个新的列year\u分组,其中包含您的年份所在的桶

在本例中,假设您的年份从2000年到2016年不等,并且您希望每4年对它们进行一次分组。以下代码将实现这一点:

df$year_grouping <- cut(df$year, c(2000:2016, 4))