View source: R/write_functions.R
mult_assign | R Documentation |
Successively assign values to variables in a dataframe at specified ids
mult_assign(df, id, df_cts)
df |
The dataframe to be modified |
id |
The name of the id column (character vector) |
df_cts |
A dataframe including the following columns: "var", "val" & "ids", such as generated, e.g., by tab_cts(df, include_ids = TRUE) |
The variables var
in the dataframe df are set to val for all
the ids in ids
. This done for every tripple of these variables
contained in the rows of df_cts
df <- data.frame(fbnr = 1:10, sex = c(2, 1, 2, 1, 1, 2, 2, 1, 2, 1), age = c(24, 23, 23, 41, 23, 39, 30, 18, 31, 48)) # Produce data summary: df_cts <- tab_cts(df, "fbnr", include_ids = TRUE) # Take the id column of df and reassign variables with all the values given in df_cts: df_copy <- mult_assign(df["fbnr"], "fbnr", df_cts) # Now both should be equal all.equal(df, df_copy)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.