R/text_number_replace.R

Defines functions text_number_replace

text_number_replace <- function(x) {

  require(tidyverse)

  comp_tbl <- tibble(number = 1:10,
                        text = c('first','second','third','fourth','fifth','sixth','seventh','eighth','ninth','tenth'))

  comp_test <- 1:nrow(comp_tbl)

  tested_value <- tibble()

  for (i in comp_test) {

    new_test <- tibble(test = ifelse(str_detect(x,comp_tbl$text[i])==TRUE,comp_test[i],0))

    tested_value <- bind_rows(tested_value,new_test)

  }

  tested_value <- tested_value %>%
    filter(!test == 0)

  value <- tested_value[['test']]

  comp_fix <- comp_tbl %>%
    filter(number == value)

  new_x <- gsub(comp_fix$text,comp_fix$number,x)

  return(new_x)

  }
neugelb/neugelbtools documentation built on July 7, 2020, 1:17 a.m.