R/shift.up.R

Defines functions shift.up

Documented in shift.up

shift.up <- function( A, rows = 1, fill = 0 )
{
###
### this function returns a matrix that has been shifted up m rows
### filling the previous rows with the given fill value
###
### Arguments
### A = a numerical matrix
### rows = number of rows to be shifed upwards
### fill = a numeric value to be used to fill the rows
###
    if ( !is.matrix( A ) ) {
        stop( "argument A is not a matrix" )
    }
    if ( !is.numeric( A ) ) {
        stop( "argument A is not a numeric matrix" )
    }    
    if ( rows != trunc( rows ) )
        stop( "Arguments rows is not an integer" )
    if ( rows < 0 )
        stop( "Argument rows is not positive" )
    if ( !is.numeric( fill ) )
        stop( "Argument fill is not numeric" )
    if ( rows > 0 )
        return( shift.up( rbind( A[2:nrow(A),], rep( fill, ncol(A) ) ),
                rows - 1, fill ) )
    return( A )    
}

Try the matrixcalc package in your browser

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

matrixcalc documentation built on Sept. 15, 2022, 1:05 a.m.