assignv_to_aaw {gmoTree} | R Documentation |
Assign a variable to all_apps_wide
Description
Assign a variable from one of the app data frames to all_apps_wide.
Usage
assignv_to_aaw(oTree, app, variable, newvar, resafter = NULL)
Arguments
oTree |
A list of data frames that were created by import_otree(). |
app |
Character. The data frame from which the variable is taken. |
variable |
Character. The name of the variable that should be assigned to all_apps_wide. |
newvar |
Character. The name of the newly created variable in the all_apps_wide data frame. |
resafter |
Character. The name of the variable that precedes the new variable. If NULL, the new variable will be placed at the end of the data frame. |
Value
This function returns a duplicate of the original oTree list of data frames but with an additional column in the all_apps_wide data frame that contains the variable in question.
Examples
# Use package-internal list of oTree data frames
oTree <- gmoTree::oTree
# Create a new variable
oTree$survey$younger30 <- ifelse(oTree$survey$player.age < 30, 0, 1)
# Assign the variable younger30 to all_apps_wide
oTree2 <- assignv_to_aaw(
oTree = oTree,
app = "survey",
variable = "younger30",
newvar = "younger30")
# Show the new variable in the all_apps_wide data frame
oTree2$all_apps_wide$younger30
# Check the position of the new variable
match("younger30",names(oTree2$all_apps_wide))
# Place the new variable immediately after the "survey.1.player.age" variable
oTree2 <- assignv_to_aaw(oTree,
app = "survey",
variable = "younger30",
newvar = "younger30",
resafter = "survey.1.player.age")
# Show the new variable in the all_apps_wide data frame
oTree2$all_apps_wide$younger30
# Show the position of the new variable
match("younger30", names(oTree2$all_apps_wide))
[Package gmoTree version 1.0.1 Index]