merge.wprof: Merge two sets of profiles.

View source: R/merge.wprof.R

merge.wprofR Documentation

Merge two sets of profiles.

Description

Method of the function merge of package base to merge two objects of class wprof generated through functions var2prof or pop2prof.

Usage

## S3 method for class 'wprof'
merge(x, y, support = FALSE, FUN = "+", all = TRUE, ...)

Arguments

x, y

objects of class wprof to be coerced to one.

support

boolean variables specifying whether y is the support of x (FALSE by default).

FUN

function to be applied to the profiles' frequencies (by default, FUN = sum). It is ignored if support is TRUE.

all

same argument of function merge, by default set to TRUE, to get all possible profiles. If a profile is not observed in the data, its frequency is set to 0.

...

additional arguments to be passed to method merge.data.frame of the package base.

Details

Objects of class wprof are composed of a data.frame of profiles and a vector of frequencies. This method applies method merge.data.frame to the profiles and applies function FUN to the frequencies.

If support is TRUE, function merge.data.frame is not used and the output corresponds to the object y, but with its frequencies modified. These are set equal to the frequencies of the corresponding profiles in x, or to 0 for profiles not contained in x.

Author(s)

Arcagni A.

See Also

merge, var2prof, pop2prof

Examples

n <- 5
v1 <- as.ordered(c("a", "b", "c", "d"))
v2 <- 1:3
set.seed(0)
pop <- data.frame(
	v1 = sample(v1, n, replace = TRUE),
	v2 = sample(v2, n, replace = TRUE)
)

survey_weights <- round(runif(5)*10)

prof1 <- pop2prof(pop, weights = survey_weights)
prof2 <- var2prof(varmod = list(v1 = as.ordered(c("a", "b", "c", "d")), v2 = 1:3))

# prof2 is the support of prof1
merge(prof1, prof2, support = TRUE)

# union between the two sets of profiles and their frequencies are added
merge(prof1, prof2)

# intersection of the sets of profiles with the assumption
# that the minimum number of observations is shared
# between the two distributions
merge(prof1, prof2, all = FALSE, FUN = min)

prof2$freq <- prof2$freq*10
# to remove from prof2 the observations in prof1
distribution <- merge(prof2, prof1, FUN = "-"); distribution

parsec documentation built on Aug. 19, 2023, 5:07 p.m.