Assign a variable from $all_apps_wide
to the other app data frames.
Arguments
- oTree
A list of data frames that were created by
import_otree
- variable
Character. The variable in the
$all_apps_wide
data frame that should be assigned to all other apps.- newvar
Character. The name of the newly created variable.
Value
This function returns a duplicate of the
original oTree list of data frames
but with an additional column in all data frames. The additional column
contains data from the specified variable found in $all_apps_wide
.
Examples
# Use package-internal list of oTree data frames
oTree <- gmoTree::oTree
# Assign variable "survey.1.player.gender" and name it "gender"
oTree <- assignv(oTree = oTree,
variable = "survey.1.player.gender",
newvar = "gender")
# Show the new variable in some of the other app data frames
oTree$dictator$gender
#> [1] "Male" "Female" "Male" "Female" "Female" "Male" "" "Male"
#> [9] "" "Male" "Female" "Male" "Female" "Female" "Male" ""
#> [17] "Male" "" "Male" "Female" "Male" "Female" "Female" "Male"
#> [25] "" "Male" "" "Female" "Female" "" "" "Female"
#> [33] "Female" "" "" "Female" "Female" "" "" "Male"
#> [41] "" "Female" "Female" "Female" "Male" "Male" "" "Female"
#> [49] "Female" "Female" "Male" "Male" "" "Female" "Female" "Female"
#> [57] "Male" "" "" "" "" "" "" ""
#> [65] "" "" "" "" "" "Female" "Female" "Female"
#> [73] "Female" "Female" "Female"
oTree$chatapp$gender
#> [1] "Male" "Female" "Male" "Female" "Female" "Male" "" "Male"
#> [9] "" "Female" "Female" "" "" "Male" "" "Female"
#> [17] "Female" "Female" "Male" "" "" "" "" "Female"
#> [25] "Female"
# The variable is now duplicated in app "survey" because it is obtained from
# there (This can be avoided by naming the new variable the same as the old
# variable)
oTree$survey$gender
#> [1] "Male" "Female" "Male" "Female" "Female" "Male" "" "Male"
#> [9] "" "Female" "Female" "" "" "Male" "" "Female"
#> [17] "Female" "Female" "Male" "" "" "" "" "Female"
#> [25] "Female"
oTree$survey$player.gender
#> [1] "Male" "Female" "Male" "Female" "Female" "Male" "" "Male"
#> [9] "" "Female" "Female" "" "" "Male" "" "Female"
#> [17] "Female" "Female" "Male" "" "" "" "" "Female"
#> [25] "Female"
# In app "all_apps_wide," the variable is also there twice (This can be
# avoided by naming the new variable the same as the old variable)
oTree$all_apps_wide$gender
#> [1] "Male" "Female" "Male" "Female" "Female" "Male" "" "Male"
#> [9] "" "Female" "Female" "" "" "Male" "" "Female"
#> [17] "Female" "Female" "Male" "" "" "" "" "Female"
#> [25] "Female" "Female" "Female" "Female" "Male"
oTree$all_apps_wide$survey.1.player.gender
#> [1] "Male" "Female" "Male" "Female" "Female" "Male" "" "Male"
#> [9] "" "Female" "Female" "" "" "Male" "" "Female"
#> [17] "Female" "Female" "Male" "" "" "" "" "Female"
#> [25] "Female" "Female" "Female" "Female" "Male"