Skip to content

Commit

Permalink
add Date1/Year to a class
Browse files Browse the repository at this point in the history
  • Loading branch information
walke committed Oct 29, 2019
1 parent 4263177 commit a16ce10
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
29 changes: 15 additions & 14 deletions R/GENESISClasses.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ NULL
#'
#' This \code{RD1} class fits to the GENESIS table 12613-02-02-4.
#' See https://www.regionalstatistik.de/genesis/online for data details.
#' An RD1 instance stores the raw header, the raw footer, the content,
#' An RD1 instance stores the raw header, the raw footer, the content,
#' the version protocol and regional information and the
#' death count information as a data.table object. Further it stores a second data.table
#' with the total sums information.
Expand All @@ -33,7 +33,7 @@ setClass("RD1",
header="vector", # file header
footer="vector", # file footer
rd1="data.table", # exposure table
rd1total="data.table", # exposure table total sums
rd1total="data.table", # exposure table total sums
content="character", # content
region="character", # region
protocol="character" # protocol version
Expand Down Expand Up @@ -204,7 +204,7 @@ setValidity("RD1",
#'
#' This \code{RE1} class fits to the GENESIS table 12411-03-03-4.
#' See https://www.regionalstatistik.de/genesis/online for data details.
#' An RE1 instance stores the raw header, the raw footer, the content,
#' An RE1 instance stores the raw header, the raw footer, the content,
#' the version protocol and regional information and the
#' exposure information as a data.table object. Further it stores a second data.table
#' with the total sums information.
Expand Down Expand Up @@ -375,7 +375,7 @@ setValidity("RE1",
function(object) {
msg <- NULL
valid <- TRUE
re1colnames <-c("Region_Code","Region_Name","Age_Name","Total1","Male","Female","D_Total","D_Male","D_Female",
re1colnames <-c("Date1","Region_Code","Region_Name","Age_Name","Total1","Male","Female","D_Total","D_Male","D_Female",
"A_Total","A_Male","A_Female", "Year", "AgeLow")
if (!all(re1colnames %in% colnames(object@re1))) {
valid <- FALSE
Expand All @@ -389,7 +389,7 @@ setValidity("RE1",
####

# read all information from 'GENESIS-Tabelle: 12613-02-02-4'
# Statistische Ämter des Bundes und der Länder, Deutschland, 2019
# Statistische &Auml;mter des Bundes und der L&auml;nder, Deutschland, 2019

#' RD1 readRegDeath
#'
Expand All @@ -415,11 +415,11 @@ readRegDeath <- function(infile)

data.table::setnames(rdft, c("V1","V2","V3","V4","V5","V6","V7","V8","V9","V10"),
c("Year","Region_Code","Region_Name","Age_Name","Total1","Male","Female","D_Total","D_Male","D_Female"))

# extract the total sums
Age_Name <- NULL # to prevent a note
rd1total <- rdft[Age_Name=="Insgesamt"]

# merge the lower age limit
age_code1 <- data.table::data.table(Age_Name=c("unter 1 Jahr","1 bis unter 5 Jahre",
"5 bis unter 10 Jahre","10 bis unter 15 Jahre",
Expand All @@ -441,7 +441,7 @@ readRegDeath <- function(infile)


# read all information from 'GENESIS-Tabelle: 12411-03-03-4'
# Statistische Ämter des Bundes und der Länder, Deutschland, 2019
# Statistische &Auml;mter des Bundes und der L&auml;nder, Deutschland, 2019

#' RE1 readRegExp
#'
Expand All @@ -465,18 +465,19 @@ readRegExp <- function(infile)

rexpt <- data.table::fread(infile, skip=h2, nrows=(f1-h2-1))

data.table::setnames(rexpt, c("V1","V2","V3","V4","V5","V6","V7","V8","V9","V10","V11","V12"),
c("Region_Code","Region_Name","Age_Name","Total1","Male","Female","D_Total","D_Male","D_Female",
data.table::setnames(rexpt, c("V1","V2","V3","V4","V5","V6","V7","V8","V9","V10","V11","V12","V13"),
c("Date1","Region_Code","Region_Name","Age_Name","Total1","Male","Female","D_Total","D_Male","D_Female",
"A_Total","A_Male","A_Female"))
# add the year
Year <- NULL # avoid NOTE
rexpt[, Year:=2016]
Year <- NULL # avoid NOTE
Date1 <- NULL # avoid NOTE
rexpt[, Year := as.integer(sub("31.12.","",Date1))]

Age_Name <- NULL # to prevent a note
# extract the total sums
re1total <- rexpt[Age_Name=="Insgesamt"]


# merge the lower age limit
age_code2 <- data.table::data.table(Age_Name=c("unter 3 Jahre","3 bis unter 6 Jahre",
"6 bis unter 10 Jahre","10 bis unter 15 Jahre",
Expand Down
2 changes: 1 addition & 1 deletion man/RD1-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/RE1-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a16ce10

Please sign in to comment.