R/psmatrix_to_recency_at_time_of_matrix.R

Defines functions psmatrix_to_recency_attimeof_matrix

Documented in psmatrix_to_recency_attimeof_matrix

#' accepts a psmatrix
#' converts 1/0 purchase strings to recency at timeof
#' @export psmatrix_to_recency_attimeof_matrix
#' @param psmatrix a psmatrix

psmatrix_to_recency_attimeof_matrix <- function(psmatrix) {
  
  rec_ato_matrix <- matrix(nrow = nrow(psmatrix), ncol = ncol(psmatrix))
  
  for (i in 1:nrow(psmatrix)) {
    for (j in 1:ncol(psmatrix)) {
      #rec_ato_matrix[i,j] <- CADF::recency_from_rle(rle(psmatrix[i, i:j]))
      rec_ato_matrix[i,j] <- 1 #needs fixed
      }
  }

  return(rec_ato_matrix)
    
  
}

Try the CADF package in your browser

Any scripts or data that you put into this service are public.

CADF documentation built on Oct. 31, 2024, 5:08 p.m.