Learn R Programming

parsec (version 1.2.0)

merge.wprof: 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 wprof
merge(x, y, support = FALSE, FUN = "+", all = TRUE, ...)

Arguments

x, y

objects of class wprof to be coerced to one.

support

boolean variables to indicate if y is the support of x, FALSE by default.

FUN

function to be applied to the profiles frequencies, by default the frequencies are added. It is ignored if support id TRUE.

all

same argument of the function merge, here set TRUE by default to get all the possible profiles. If a profile is not observed its frequency is equal to 0, but it does not mean that it is not possible to observe it.

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

Details

Objects of class wprof are composed by a data.frame of profiles and a vector of frequencies. This method applies the method merge.data.frame to the first the profiles and applies the 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 its frequencies are modified. Frequencies are equal to the frequencies of the corresponding profiles in x or are equal to 0 if the corresponding profile is not contained in x.

See Also

merge, var2prof, pop2prof

Examples

Run this code
# NOT RUN {
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
# }

Run the code above in your browser using DataLab