R/env.R

Defines functions divide_list

divide_list <- function(x, number = 50) {
  
  if (length(x) > number) {
    rest <- length(x) %% number
    
    if (rest == 0) {
      
      result <- matrix(x, ncol = number, byrow = TRUE)
      result <- split(result, row(result))
      
    } else {
      
      index <- length(x) - rest
      
      result <- matrix(x[1:index], ncol = number, byrow = TRUE) %>%
        split(., row(.))
      
      result[[length(result) + 1]] <- x[(index + 1):length(x)]
    
    }
    
    result %<>% sapply(paste,collapse = "|")
    
  } else {
    
    result <- paste(as.vector(x),collapse = "|")
    
  }
  
  unname(result)
  
}
cafeine05/WikiSocio documentation built on Nov. 17, 2018, 10:01 a.m.