Delete specific cases from all data frames in the oTree list.
Caution 1: This function does not delete cases from the original CSV and Excel files!
Caution 2: This function does not delete cases from custom exports and custom data frames if these data frames do not have a variable named participant.code!
Caution 3: This function does not delete any data from
the $Chats
data frame!
(As the interpretation of chat data depends on how participants
engage with each other, the data must be deleted
with more care than deleting data in other apps.
Hence, this function does not delete data in this data frame.
Please do this manually if necessary!)
Usage
delete_cases(
oTree,
pcodes = NULL,
plabels = NULL,
saved_vars = NULL,
reason,
omit = FALSE,
info = FALSE
)
Arguments
- oTree
A list of data frames that were created by
import_otree
.- pcodes
Character. The value(s) of the participant.code variable of the participants whose data should be removed.
- plabels
Character. The value(s) of the participant.label variable of the participants whose data should be removed.
- saved_vars
Character. The name(s) of variable(s) that need(s) to be stored in the list of information on deleted cases in
$info$deleted_cases
.- reason
Character. The reason for deletion that should be stored in the list of information on deleted cases in
$info$deleted_cases
.- omit
Logical.
TRUE
if the deleted cases should not be added to the information on deleted cases in$info$deleted_cases
.- info
Logical.
TRUE
if a brief information on the case deletion process should be printed.
Value
This function returns a duplicate of the original oTree list of data frames that do not include the deleted cases.
It adds information on the deleted cases to $info$deleted_cases
. (This
list is also filled by other functions.)
In this list, you can find the following information:
- $codes
= A vector with the participant codes of all deleted cases.
- $count
= The number of participants in $codes
.
- $full
and $unique
= The data frames $full
and $unique
contain information on each deleted participant and the reason why they were deleted. The entries to the $full
and the $unique
data frames are the same. Columns "end_app"
and "end_page"
are left empty intentionally because they are only filled by the delete_dropouts
function.
Examples
# Use package-internal list of oTree data frames
oTree <- gmoTree::oTree
# Delete only one case
oTree2 <- delete_cases(oTree,
pcodes = "xmxl46rm",
reason = "requested")
# Show changes in row numbers
print(paste("Row numbers before deletion: ", nrow(oTree$all_apps_wide), nrow(oTree$survey),
nrow(oTree$Time), nrow(oTree$Chats)))
#> [1] "Row numbers before deletion: 29 25 289 35"
print(paste("Row numbers after deletion: ", nrow(oTree2$all_apps_wide), nrow(oTree2$survey),
nrow(oTree2$Time), nrow(oTree2$Chats)))
#> [1] "Row numbers after deletion: 28 24 275 35"
# Delete several cases
deletionlist <- c("4zhzdmzo", "xmxl46rm")
oTree2 <- delete_cases(oTree,
pcodes = deletionlist,
reason = "requested")
# Show row numbers again
print(paste(nrow(oTree2$all_apps_wide), nrow(oTree2$survey),
nrow(oTree2$Time), nrow(oTree2$Chats)))
#> [1] "27 23 258 35"
# Show information on all deleted cases (also dropouts):
oTree2$info$deleted_cases$full
#> participant.code session end_app end_page reason
#> 3 4zhzdmzo 7bfqtokx requested
#> 12 xmxl46rm vd1h01iv requested
# Save one variable
oTree2 <- delete_cases(oTree,
pcodes = deletionlist,
reason = "requested",
saved_vars = "participant._index_in_pages")
# Show row numbers again
print(paste(nrow(oTree2$all_apps_wide), nrow(oTree2$survey),
nrow(oTree2$Time), nrow(oTree2$Chats)))
#> [1] "27 23 258 35"
# Check the "full" deletion information
oTree2$info$deleted_cases$full
#> participant.code session end_app end_page reason
#> 3 4zhzdmzo 7bfqtokx requested
#> 12 xmxl46rm vd1h01iv requested
#> participant._index_in_pages
#> 3 17
#> 12 17
# Save some variables
oTree2 <- delete_cases(oTree,
pcodes = deletionlist,
reason = "requested",
saved_vars = c(
"participant._index_in_pages",
"participant._max_page_index"))
# Show row numbers again
print(paste(nrow(oTree2$all_apps_wide), nrow(oTree2$survey),
nrow(oTree2$Time), nrow(oTree2$Chats)))
#> [1] "27 23 258 35"
# Check the "full" deletion information
oTree2$info$deleted_cases$full
#> participant.code session end_app end_page reason
#> 3 4zhzdmzo 7bfqtokx requested
#> 12 xmxl46rm vd1h01iv requested
#> participant._index_in_pages participant._max_page_index
#> 3 17 16
#> 12 17 16
# Get a list of all deleted cases
# (If there is already a list, the new list is added to it)
oTree2$info$deleted_cases$codes
#> [1] "4zhzdmzo" "xmxl46rm"
# Show number of all deleted cases
length(oTree2$info$deleted_cases$codes)
#> [1] 2
oTree2$info$deleted_cases$count
#> [1] 2
# Delete a session and delete a single case from another session
oTree2 <- delete_sessions(oTree,
scodes = c("vd1h01iv"),
reason = "Server Crash",
saved_vars = "dictator.1.group.id_in_subsession")
oTree2 <- delete_cases(oTree2,
pcodes = "4zhzdmzo",
reason = "requested")
# Check the "full" deletion information
oTree2$info$deleted_cases$full
#> participant.code session.code dictator.1.group.id_in_subsession end_app
#> 1 xx78b3x0 vd1h01iv 1
#> 2 xmxl46rm vd1h01iv 1
#> 3 vbhvhozv vd1h01iv 2
#> 4 2scvem7a vd1h01iv 2
#> 5 4zhzdmzo <NA> NA
#> end_page reason session
#> 1 Server Crash <NA>
#> 2 Server Crash <NA>
#> 3 Server Crash <NA>
#> 4 Server Crash <NA>
#> 5 requested 7bfqtokx
# See codes of deleted variables
oTree2$info$deleted_cases$codes
#> [1] "4zhzdmzo" "xx78b3x0" "xmxl46rm" "vbhvhozv" "2scvem7a"
# See number of deleted variables
oTree2$info$deleted_cases$count
#> [1] 5