R/count_of_unique_in_redundant_vector.R

Defines functions count_of_unique_in_redundant_vector

Documented in count_of_unique_in_redundant_vector

#' Count unique elements in dedundant vector
#' @param inVec A redundant vector of any type
#' @return A data frame where first column contains unique elements while second their respective counts
#' @export 

count_of_unique_in_redundant_vector = function(inVec){
  o = as.data.frame(matrix(nrow = 1,ncol = 2))
  u = unique(inVec)
  for(i in 1:length(u)){
    c = countOfsomething.2(inVec,u[i])
    r = c(u[i],c)
    o = rbind(o,r)
  }
  
  o = o[-1,]
  o = o[order(o[,1]),]
  colnames(o) = c("uniqueElement", "count")
  row.names(o) = o[,1]
  return(o)
}
msxakk89/dat documentation built on Aug. 3, 2020, 6:39 p.m.