delete_cases {gmoTree}R Documentation

Delete specific cases

Description

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

# First, show some row numbers
print(paste(nrow(oTree$all_apps_wide), nrow(oTree$survey),
nrow(oTree$Time), nrow(oTree$Chats)))

# Delete only one case
oTree2 <- delete_cases(oTree,
                       pcodes = "xmxl46rm",
                       reason = "requested")

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

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

# Show information on all deleted cases (also dropouts):
oTree2$info$deleted_cases$full

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

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

# 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

# Show number of all deleted cases
length(oTree2$info$deleted_cases$codes)
oTree2$info$deleted_cases$count

[Package gmoTree version 1.0.1 Index]