Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

group_names

extract and set group names


Description

extract and set group names

Usage

group_names(x, value)

group_names(x) <- value

## Default S3 method:
group_names(x, value)

## Default S3 replacement method:
group_names(x) <- value

## S3 method for class 'incidence'
group_names(x, value = NULL)

## S3 replacement method for class 'incidence'
group_names(x) <- value

Arguments

x

an incidence() object.

value

character vector used to rename groups

Details

This accessor will return a

Value

an integer indicating the number of groups present in the incidence object.

Examples

i <- incidence(dates = sample(10, 100, replace = TRUE), 
               interval = 1L,
               groups = sample(letters[1:3], 100, replace = TRUE))
i
group_names(i)

# change the names of the groups
group_names(i) <- c("Group 1", "Group 2", "Group 3")
i

# 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))

# 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))
colSums(get_counts(i))  # original still has three groups
colSums(get_counts(ii))
# with side-effects
group_names(i) <- gname
colSums(get_counts(i))

incidence

Compute, Handle, Plot and Model Incidence of Dated Events

v1.7.3
MIT + file LICENSE
Authors
Thibaut Jombart [aut], Zhian N. Kamvar [aut] (<https://orcid.org/0000-0003-1458-7108>), Rich FitzJohn [aut], Tim Taylor [cre] (<https://orcid.org/0000-0002-8587-7113>), Jun Cai [ctb] (<https://orcid.org/0000-0001-9495-1226>), Sangeeta Bhatia [ctb], Jakob Schumacher [ctb], Juliet R.C. Pulliam [ctb] (<https://orcid.org/0000-0003-3314-8223>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.