Assign a variable from one of the app data frames to $all_apps_wide
.
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
# Check out the old variable
oTree$survey$player.age
#> [1] 22 22 23 23 33 45 NA 44 NA 33 23 NA NA 23 NA 44 21 23 23 NA NA NA NA 34 20
# Create a new variable
oTree$survey$younger30 <- ifelse(oTree$survey$player.age < 30, 1, 0)
# Assign the variable younger30 to all_apps_wide
oTree2 <- assignv_to_aaw(
oTree = oTree,
app = "survey",
variable = "younger30",
newvar = "younger30")
#> Warning: New variable is created. However, there is an unequal number of participants in "all_apps_wide" (29) and app "survey" (25). Did you forget to delete dropouts and empty cases or did you forget to import app data? Sometimes, this can happen if you import data from within a session or room where you can only import "all_apps_wide" but not the separate app data, time data or chat data.
# Show the new variable in the all_apps_wide data frame
oTree2$all_apps_wide$younger30
#> [1] 1 1 1 1 0 0 NA 0 NA 0 1 NA NA 1 NA 0 1 1 1 NA NA NA NA 0 1
#> [26] NA NA NA NA
# Check the position of the new variable
match("younger30",names(oTree2$all_apps_wide))
#> [1] 56
# 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")
#> Warning: New variable is created. However, there is an unequal number of participants in "all_apps_wide" (29) and app "survey" (25). Did you forget to delete dropouts and empty cases or did you forget to import app data? Sometimes, this can happen if you import data from within a session or room where you can only import "all_apps_wide" but not the separate app data, time data or chat data.
# Show the new variable in the all_apps_wide data frame
oTree2$all_apps_wide$younger30
#> [1] 1 1 1 1 0 0 NA 0 NA 0 1 NA NA 1 NA 0 1 1 1 NA NA NA NA 0 1
#> [26] NA NA NA NA
# Show the position of the new variable
match("younger30", names(oTree2$all_apps_wide))
#> [1] 50