Learn R Programming

gmoTree (version 1.4.1)

delete_sessions: Delete all cases of one session

Description

Delete cases from specific sessions in all data frames within the list of data frames.

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 if the custom exports do not have a variable named participant.code and a variable named session.code!

Usage

delete_sessions(oTree, scodes, saved_vars = NULL, reason, info = FALSE)

Value

This function returns a duplicate of the original oTree list of data frames that do not include the deleted sessions.

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:

  • $full and $unique = The data frames $full and $unique contain information on all participants whose data were deleted. The entries to the $full and the $unique data frames in this list are the same. Columns end_app and end_page are left empty intentionally because they are only filled by the delete_dropouts() function. Columns participant.code and reason are filled.

  • $codes = A vector containing the participant codes of all deleted participants.

  • $count = The number of all deleted participants.

Arguments

oTree

A list of data frames created with import_otree().

scodes

Character string or character vector. The session.code(s) of the session(s) whose data should be removed.

saved_vars

Character string or character vector. 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 string. The reason for deletion that should be stored in the list of information on deleted cases in $info$deleted_cases.

info

Logical. TRUE if a brief information on the session deletion process should be printed.

Examples

Run this code
# Use package-internal list of oTree data frames
oTree <- gmoTree::oTree

# Delete one session
oTree2 <- delete_sessions(oTree,
  scodes = "7bfqtokx",
  reason = "Only tests")

# 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)))

print(paste("Row numbers after deletion: ",
  nrow(oTree2$all_apps_wide), nrow(oTree2$survey),
  nrow(oTree2$Time), nrow(oTree2$Chats)))

# Delete two sessions and show deletion message
oTree2 <- delete_sessions(oTree,
  scodes = c("7bfqtokx", "vd1h01iv"),
  reason = "Only tests",
  info = TRUE)

# Show row numbers again
print(paste(nrow(oTree2$all_apps_wide), nrow(oTree2$survey),
  nrow(oTree2$Time), nrow(oTree2$Chats)))

# Delete session and save variable to the info list
oTree2 <- delete_sessions(oTree,
  scodes = c("7bfqtokx", "vd1h01iv"),
  reason = "Server Crash",
  saved_vars = "dictator.1.group.id_in_subsession")

# Check the "full" deletion information
oTree2$info$deleted_cases$full

# See codes of deleted variables
oTree2$info$deleted_cases$codes

# See number of deleted variables
oTree2$info$deleted_cases$count

# Delete a single case and then delete a session
oTree2 <- delete_cases(oTree,
  pcodes = "4zhzdmzo",
  reason = "requested")
oTree2 <- delete_sessions(oTree2,
  scodes = c("vd1h01iv"),
  reason = "Server Crash",
  saved_vars = "dictator.1.group.id_in_subsession")

# Check the "full" deletion information
oTree2$info$deleted_cases$full

# See codes of deleted variables
oTree2$info$deleted_cases$codes

# See number of deleted variables
oTree2$info$deleted_cases$count

Run the code above in your browser using DataLab