
Rename subjects in the data via pattern detection
Source:R/utility_functions.R
rename_viewr_characters.RdQuick utility function to use str_replace with mutate(across()) to batch- rename subjects via pattern detection.
Value
A tibble or data frame in which subjects have been renamed according
to the pattern and replacement supplied by the user.
Examples
## 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)
#> [1] "device02" "device03" "device05"
## 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)
#> [1] "subject02" "subject03" "subject05"