Skip to contents

The mark_location() function creates a column labeling rows that have locations outside of the US. The function is written to work with data from Qualtrics surveys.


  id_col = "ResponseId",
  location_col = c("LocationLatitude", "LocationLongitude"),
  rename = TRUE,
  include_na = FALSE,
  quiet = FALSE,
  print = TRUE



Data frame (preferably imported from Qualtrics using {qualtRics}).


Column name for unique row ID (e.g., participant).


Two element vector specifying columns for latitude and longitude (in that order).


Logical indicating whether to rename columns (using rename_columns())


Logical indicating whether to include rows with NA in latitude and longitude columns in the output list of potentially excluded data.


Logical indicating whether to print message to console.


Logical indicating whether to print returned tibble to console.


An object of the same type as x that includes a column marking rows that are located outside of the US and (if include_na == FALSE) rows with no location information. For a function that checks for these rows, use check_location(). For a function that excludes these rows, use exclude_location().


To record this information in your Qualtrics survey, you must ensure that Anonymize responses is disabled.

Default column names are set based on output from the qualtRics::fetch_survey(). The function only works for the United States. It uses the #' maps::map.where() to determine if latitude and longitude are inside the US.

The function outputs to console a message about the number of rows with locations outside of the US.

See also

Other location functions: check_location(), exclude_location()

Other mark functions: mark_duplicates(), mark_duration(), mark_ip(), mark_preview(), mark_progress(), mark_resolution()


# Mark locations outside of the US
df <- mark_location(qualtrics_text)
#>  1 out of 100 rows had no information on location.
#>  5 out of 100 rows were located outside of the US.

# Remove preview data first
df <- qualtrics_text %>%
  exclude_preview() %>%
#>  2 out of 100 preview rows were excluded, leaving 98 rows.
#>  1 out of 98 rows had no information on location.
#>  5 out of 98 rows were located outside of the US.