rename_viewr_characters: Rename subjects in the data via pattern detection

Description Usage Arguments Value Author(s) See Also Examples

View source: R/utility_functions.R

Description

Quick utility function to use str_replace with mutate(across()) to batch- rename subjects via pattern detection.

Usage

1
2
3
4
5
6
rename_viewr_characters(
  obj_name,
  target_column = "subject",
  pattern,
  replacement = ""
)

Arguments

obj_name

The input viewr object; a tibble or data.frame with attribute pathviewr_steps that includes "viewr"

target_column

The target column; defaults to "subject"

pattern

The (regex) pattern to be replaced

replacement

The replacement text. Must be a character

Value

A tibble or data frame in which subjects have been renamed according to the pattern and replacement supplied by the user.

Author(s)

Vikram B. Baliga

See Also

Other data cleaning functions: gather_tunnel_data(), get_full_trajectories(), quick_separate_trajectories(), redefine_tunnel_center(), relabel_viewr_axes(), rotate_tunnel(), select_x_percent(), separate_trajectories(), standardize_tunnel(), trim_tunnel_outliers(), visualize_frame_gap_choice()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
## Import the example Motive data included in the package
motive_data <-
  read_motive_csv(system.file("extdata", "pathviewr_motive_example_data.csv",
                             package = 'pathviewr'))

## Clean the file. It is generally recommended to clean up to the
## "gather" step before running rescale_tunnel_data().
 motive_gathered <-
   motive_data %>%
   relabel_viewr_axes() %>%
   gather_tunnel_data()

## See the subject names
 unique(motive_gathered$subject)

## Now rename the subjects. We'll get rid of "device" and replace it
## with "subject"
motive_renamed <-
  motive_gathered %>%
  rename_viewr_characters(target_column = "subject",
                          pattern = "device",
                          replacement = "subject")

## See the new subject names
unique(motive_renamed$subject)

pathviewr documentation built on May 6, 2021, 9:07 a.m.