MatthieuStigler / matPkg

Other
2 stars 0 forks source link

mat_keep_first: only remove sequential ones #39

Open MatthieuStigler opened 4 years ago

MatthieuStigler commented 4 years ago

Problem is if item is repeated multiple times! AAA BBB AAA want A B A

code below should do it:

here_remv_repeat <- function(x) {
  if(!is.factor(x)) x <-  as.factor(x)
  x_char <- as.character(x)
  x_num <- as.numeric(x)
  x_rep <- c(1, diff(x_num))
  x_char[x_rep==0] <- ""
  x_char
}