extract and set group names
group_names(x, value) group_names(x) <- value # S3 method for default group_names(x, value) # S3 method for default group_names(x) <- value # S3 method for incidence group_names(x, value = NULL) # S3 method for incidence group_names(x) <- value
x | an |
---|---|
value | character vector used to rename groups |
an integer indicating the number of groups present in the incidence object.
This accessor will return a
i <- incidence(dates = sample(10, 100, replace = TRUE), interval = 1L, groups = sample(letters[1:3], 100, replace = TRUE)) i#> <incidence object> #> [100 cases from days 1 to 10] #> [3 groups: a, b, c] #> #> $counts: matrix with 10 rows and 3 columns #> $n: 100 cases in total #> $dates: 10 dates marking the left-side of bins #> $interval: 1 day #> $timespan: 10 days #> $cumulative: FALSE #>group_names(i)#> [1] "a" "b" "c"#> <incidence object> #> [100 cases from days 1 to 10] #> [3 groups: Group 1, Group 2, Group 3] #> #> $counts: matrix with 10 rows and 3 columns #> $n: 100 cases in total #> $dates: 10 dates marking the left-side of bins #> $interval: 1 day #> $timespan: 10 days #> $cumulative: FALSE #># example if there are mistakes in the original data, e.g. # something is misspelled set.seed(50) grps <- sample(c("child", "adult", "adlut"), 100, replace = TRUE, prob = c(0.45, 0.45, 0.05)) i <- incidence(dates = sample(10, 100, replace = TRUE), interval = 1L, groups = grps) colSums(get_counts(i))#> adlut adult child #> 6 49 45# If you change the name of the mis-spelled group, it will be merged with the # correctly-spelled group gname <- group_names(i) gname[gname == "adlut"] <- "adult" # without side-effects print(ii <- group_names(i, gname))#> <incidence object> #> [100 cases from days 1 to 10] #> [2 groups: adult, child] #> #> $counts: matrix with 10 rows and 2 columns #> $n: 100 cases in total #> $dates: 10 dates marking the left-side of bins #> $interval: 1 day #> $timespan: 10 days #> $cumulative: FALSE #>#> adlut adult child #> 6 49 45#> adult child #> 55 45#> adult child #> 55 45