R/str_funs.R

Defines functions StrUniqueChar StrSubPosition StrDeletePosition StrInsertSpace

StrInsertSpace = function(X){
  xs = c()
  for (ii in X) {
    X1 = unlist(strsplit(ii,split = '',fixed = T))
    xs = c(xs,paste0(as.vector(matrix(c(X1,rep(' ',times = length(X1))), byrow = T,nrow = 2)),
                     collapse = ''))
  }
  xs
}

StrDeletePosition = function(X,position){
  X %>% strsplit(x = .,split = '',fixed = T) %>% unlist() %>%
    .[-c(position)] %>% paste0(collapse = '')
}

StrSubPosition = function(X,position){
  X %>% strsplit(x = .,split = '',fixed = T) %>% unlist() %>%
    .[c(position)] %>% paste0(collapse = '')
}

StrUniqueChar = function(X){
  X %>% strsplit(x = .,split = '',fixed = T) %>% unlist() %>% unique() %>% length()
}
usplos/YawMMF documentation built on July 12, 2024, 1:35 a.m.