Function

コメント・参照等
  • 時系列データを年月と年で分割する関数

FUN = f_split_tsdata.r
function (df) 
{
    df$yearmon <- paste0(year(df$Date), month(df$Date))
    df$year <- year(df$Date)
    df_monthly <- lapply(unique(df$yearmon), function(x) {
        df[df$yearmon == x, -which(names(df) %in% c("year", "yearmon"))]
    })
    df_yearly <- lapply(unique(df$yaer), function(x) df[df$yaer == x, -which(names(df) %in% c("year", "yearmon"))])
    return(list(df_monthly = df_monthly, df_yearly = df_yearly))
}