Skip to content

Process and aggregate the Corona statistic of Duisburg (xlsx) #23

@ablaette

Description

@ablaette
library(openxlsx)
library(tibble)
library(lubridate)
library(zoo)

db <- openxlsx::read.xlsx(
  xlsxFile = "~/Downloads/Corona 01.04.2022.xlsx",
  sheet = "Tabelle1"
)
db <- as_tibble(db)

for (i in 2:5){
  new_col <- gsub("\\.", "", db[[i]])
  new_col <- gsub("^.*?(\\d+).*?$", "\\1", new_col, perl = TRUE)
  db[[i]] <- as.integer(new_col)
}

date_raw <- gsub("^.*?(\\d.*\\d).*?$", "\\1", db[["Datum"]])
db[["Datum"]] <- as.Date(date_raw, format = "%d.%m.%Y")
colnames(db) <- c("date", "cases_confirmed", "infected", "recovered", "died")

db_sorted <- db[order(db$date),]

db_sorted[["new"]] <- c(
  NA,
  db_sorted$cases_confirmed[2:nrow(db_sorted)] - db_sorted$cases_confirmed[1:(nrow(db_sorted) - 1)]
)

db_sorted$month <- as.yearmon(db_sorted$date)

y <- aggregate(
  x = db_sorted[, c("month", "new")],
  by = list(mon = db_sorted$month),
  mean, na.rm = TRUE
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions