Function

コメント・参照等

FUN = f_read_seimeihyou.r
function (download_folder) 
{
    lapply(c("XLConnect", "Nippon"), require, character.only = T)
    path_to_folder <- paste0("C:/Users/", Sys.info()["user"], download_folder)
    setwd(path_to_folder)
    xls_files <- dir()
    xls_files <- sort(xls_files, decreasing = F)
    for (iii in seq(xls_files)) {
        sheet_name <- zen2han(XLConnect::getSheets(XLConnect::loadWorkbook(xls_files[iii])))
        buf0 <- readWorksheetFromFile(xls_files[iii], sheet = 1, check.names = F, header = F)
        buf1 <- f_remove_blank_row_and_column(df = buf0)
        buf2 <- f_fill_cells_column_direction(df = buf1, row = 3, below_check = F)
        colnames(buf2) <- gsub(":NA", "", sapply(paste0(buf2[3, ], ":", buf2[4, ]), zen2han))
        buf3 <- buf2[-c(1:4), ]
        buf3$`死亡率:nqx` <- as.numeric(buf3$`死亡率:nqx`)
        buf4 <- buf3[!is.na(buf3$`死亡率:nqx`), ]
        buf4$年齢 <- sapply(buf4$年齢, zen2han)
        tmp <- NA
        for (rrr in seq(nrow(buf4))) {
            if (buf4[rrr, 2] != "NA") {
                tmp <- buf4[rrr, 2]
            }
            buf4[rrr, 2] <- tmp
        }
        buf4$シート名 <- sheet_name
        if (iii == 1) {
            datadf <- buf4
        }
        else {
            datadf <- rbind(datadf, buf4)
        }
    }
    row.names(datadf) <- NULL
    datadf[, -c(2, 9)] <- apply(datadf[, -c(2, 9)], 2, function(x) as.numeric(gsub("\\s", "", x)))
    datadf$`1死亡数当たり生存数` <- round(datadf$`生存数:lx`/datadf$`死亡数:ndx`)
    datadf <- datadf[, c(9, 1:8, 10)]
    return(datadf)
}