在R中挣扎多年

时间:2014-10-18 15:43:32

标签: r grouping

截至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)。

这些年我该怎么做?

2 个答案:

答案 0 :(得分:0)

您的年份是数字吗?

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

cut <- cut(years, breaks = 2)

答案 1 :(得分:0)

让我们说您的年份存储在标有year的数据框列中。您的数据框为df,您想要一个包含&#34;存储桶的新列year_grouping&#34;你的岁月落空了。

在此示例中,假设您的年份范围为2000 - &gt; 2016年,您希望每4年对它们进行一次分组。以下代码将实现此目的:

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