陳家瑋

在 R 中建立一個空的資料框

2023-12-18


建立一個空的 data.frame

summary_duplicated_dataframe <- data.frame(
    list(
        filename = character(),
        normal_record = integer(),
        duplicated_record = integer()
    )
)

另一個範例,建立一個空的 tibble

generate_empty_dataframe <- \() {
    df <- c(
        "filename",
        "year",
        "month",
        "duplicated_rows",
        "duplicated_rows_num",
        "num_of_rows"
    ) %>%
        paste(collapse = ",") %>%
        I() %>%
        readr::read_csv(
            col_types = "ciicii"
        )
    return(df)
}