| merge.wprof {parsec} | R 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 |
support |
boolean variables specifying whether |
FUN |
function to be applied to the profiles' frequencies (by default, FUN = |
all |
same argument of function |
... |
additional arguments to be passed to method |
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
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