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, sampled_ind = "already_sampled_ind")
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 |
sampled_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. |
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
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.
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 <- new_multiwave(phases = 2, waves = c(1, 3))
get_data(MySurvey, phase = 1, slot = "data") <-
data.frame(dplyr::select(iris, -Sepal.Width))
get_data(MySurvey, phase = 2, wave = 1, slot = "sampled_data") <-
dplyr::select(iris, id, Sepal.Width)[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.