merge_samples | R Documentation |
In an object of class "Mutiwave"
, merge_samples
creates
a dataframe in the "data"
slot of the specified wave by merging
the dataframe in the "sampled data"
slot with the dataframe in
the "data"
slot of the previous wave.
merge_samples(
x,
phase,
wave,
id = NULL,
phase_sample_ind = "sampled_phase",
wave_sample_ind = "sampled_wave",
include_probs = NULL
)
x |
an object of class |
phase |
A numeric value specifying the phase of the Multiwave object that the specified wave is in. Cannot be phase 1. |
wave |
A numeric value specifying the wave of the Multiwave
object that the merge should be
performed in. This wave must have a valid dataframe in the
|
id |
A character value specifying the name of the column holding unit
ids. Taken from wave, phase, or overall metadata (searched for in that
order) if |
phase_sample_ind |
a character value specifying the name of the column that should hold the indicator of whether each unit has already been sampled in the current phase. The specified phase number will be appended to the end of the given character name. Defaults to "sampled_phase". |
wave_sample_ind |
a character value specifying the name of the column that should hold the indicator of whether each unit has already been sampled in the current wave. The specified phase and wave numbers separated by "." will be appended o the end of the given character name. If FALSE, no such column is created. Defaults to "sampled_wave". |
include_probs |
A logical value. If TRUE, looks for "probs" in
the |
Columns in "sampled_data"
that do not match names of the
"data"
from the previous wave will be added as new columns in
the output dataframe. All ids that do not appear in
"sampled_data"
will receive NA values for these new variables.
If a column name in the "sampled_data"
matches a column name in
the "data"
slot of the previous wave, these columns will be
merged into one column with the same name in the output dataframe.
For ids that have non-missing values in both columns of the merge,
the value from "sampled_data"
will overwrite the previous value
and a warning will be printed. All ids present in the "data"
from the
previous wave but missing from "sampled_data"
will be given NA values
for the newly merged variables.
If columns with the name produced by phase_sample_ind
or
wave_sample_ind
already exist, they will be overwritten.
A Multiwave object with the merged dataframe in the
"data"
slot of the specified wave.
library(datasets)
iris <- data.frame(iris, id = 1:150)
MySurvey <- multiwave(phases = 2, waves = c(1, 3))
set_mw(MySurvey, phase = 1, slot = "data") <-
data.frame(dplyr::select(iris, -Sepal.Width))
set_mw(MySurvey, phase = 2, wave = 1, slot = "sampled_data") <-
dplyr::select(iris, id, Sepal.Width)[1:40, ]
set_mw(MySurvey, phase = 2, wave = 1, slot = "samples") <-
list(ids = 1:40)
MySurvey <- merge_samples(MySurvey, phase = 2, wave = 1, id = "id")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.