Function

コメント・参照等

FUN = f_read_KoukougyouShisuu.r
function (download_folder) 
{
    f_transform <- function(tmp0) {
        tmp1 <- t(tmp0[3:nrow(tmp0), 1:ncol(tmp0)])
        colnames(tmp1) <- sapply(paste0(tmp0[1, 1], ":", tmp1[2, ], ":", tmp1[1, ], ":", tmp1[3, ]), zen2han)
        tmp2 <- tmp1[-c(1:3), ]
        tmp2[, 1] <- gsub("^[a-z][^0-9]*", "", tmp2[, 1])
        tmp3 <- data.frame(Date = as.Date(paste0(substring(tmp2[, 1], 1, 4), "-", substring(tmp2[, 1], 5, 6), "-1")), tmp2[, -1], check.names = F, stringsAsFactors = F, row.names = NULL)
        tmp3[, -1] <- apply(tmp3[, -1], 2, as.numeric)
        return(tmp3)
    }
    path_to_folder <- paste0("C:/Users/", Sys.info()["user"], download_folder)
    setwd(path_to_folder)
    zip_list <- dir(pattern = "\\.zip$")
    alldata <- Reduce(function(x, y) merge(x, y, by = "Date", all = T), lapply(zip_list, function(x) {
        csv_list <- unzip(x)
        buf0 <- lapply(gsub("\\./", "", csv_list), function(x) read.csv(file = x, encoding = "cp932", check.names = F, row.names = NULL, stringsAsFactors = F, header = F))
        Reduce(function(x, y) merge(x, y, by = "Date", all = T), lapply(grep("月次", lapply(buf0, function(x) x[1, 1])), function(x) f_transform(buf0[[x]])))
    }))
    colnames(alldata)[-1] <- paste0("鉱工業指数:", colnames(alldata)[-1])
    return(alldata)
}