R/raggedEdge.R

Defines functions raggedEdge

Documented in raggedEdge

#' Generate a ragged edge structure for a data matrix 
#' 
#' @param X numeric data matrix 
#' @param lags vector of integers representing publication lag of each variable 
#' 
#' @return ragged edge version of X
#' 
#' @examples
#' data = matrix(rnorm(100),ncol=10)
#' pub_lags = c(rep(2,5),rep(1,3),rep(0,2))
#' new_data = raggedEdge(data, pub_lags)
#' 
#' 
#' @export


raggedEdge <- function(X, lags){
  
  Y = X
  nr = nrow(X)
  nc = ncol(X)
  
  for(i in 1:nc){
    lg = lags[i]
    if(lg>0){
      Y[(nr-lg+1):nr,i] = NA
    }
  }
  return(Y)
}

Try the sparseDFM package in your browser

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

sparseDFM documentation built on March 31, 2023, 10:15 p.m.