Topic: Utilities

Topic Description:

Basic R utilities used in many packages and functions, such as date and string manipulations, statistical distributions, geometry of lines and distances. The R package date is required for the two data functions.



File: utilities/utilities.r

View File Source Download File No help file available

Function: IfElse

Function Description: IfElse

A more convenient version of the R function ifelse in cases where test, a, and b are atomic.

Function Arguments:

ArgumentDefault Value
test
a
b

Function Source:

IfElse=function(test,a,b)
{
if(test) return(a)
else return(b)
}

#
#
#
# AssignDiag
#

#

# A way to assign the diagonals of a matrix that can handle input having no dimensions. Ordinarily,
        x is square matrix and newdiag is a vector equal in length to x's diagonal.
# A new x is returned having the newdiag on its diagonal. In that usage, it matches the assign optio
        n for R's function diag.
# This improves diag by handling x with no dimensions, ie a scalar, or just one dimension. Then newd
        iag is simply returned. #

#
#
#

#
#
#

#
AssignDiag=function(x,newdiag)
{
if(is.null(dim(x))) return(newdiag)
if(length(dim(x))==0) return(newdiag)
diag(x)=newdiag
return(x)
}