Function

コメント・参照等
  • Tidy dataに変換する関数

FUN = f_convert_to_TidyData.r
function (data0, col_date = 1, key_factor = T) 
{
    data <- data0[, c(col_date, setdiff(seq(ncol(data0)), col_date))]
    tidydata <- Reduce(function(x, y) rbind(x, y), lapply(tail(seq(ncol(data)), -1), function(x) gather(data = na.omit(data[, c(1, x)]), key = "key", value = "value", colnames(data)[x])))
    if (key_factor) {
        tidydata$key <- factor(tidydata$key, levels = unique(tidydata$key))
    }
    return(tidydata)
}

Asset Management Consulting Corporation