Sorting data frame based on month-year time format

后端 未结 6 2114
孤城傲影
孤城傲影 2021-01-03 06:29

I\'m struggling with something very basic: sorting a data frame based on a time format (month-year, or, “%B-%y” in this case). My goal is to calculate various monthly statis

6条回答
  •  礼貌的吻别
    2021-01-03 07:04

    An old post but worthy of a data.table approach:

    Read in data and set local as described by @caracal

    > Sys.setlocale(category="LC_TIME", locale="Dutch_Belgium.1252")
    [1] "Dutch_Belgium.1252"
    > tmp09 <- read.table(file="clipboard", header=TRUE)
    > tmp09$ExitTime <- as.Date(tmp09$ExitTime)
    

    Summarise data as requested

    require(data.table)
    > data.table(tmp09)[, 
    +                   .(Tmp09Total = sum(AccountValue)),
    +                   by = .(Date = format(ExitTime, "%B-%y"))]
              Date Tmp09Total
    1:    april-07       6997
    2:      mei-07      21197
    3:     juli-07      29147
    4: augustus-07       7897
    5: november-07       7423
    

提交回复
热议问题