Learn R Programming

sirt (version 0.34-36)

matrixfunctions.sirt: Some Matrix Functions

Description

Some matrix functions which are written in Rcpp for speed reasons.

Usage

rowMaxs.sirt(matr)      # rowwise maximum

rowMins.sirt(matr)      # rowwise minimum

rowCumsums.sirt(matr)   # rowwise cumulative sum

rowIntervalIndex.sirt(matr,rn) # first index in row nn when matr(nn,zz) > rn(nn)

rowKSmallest.sirt(matr , K , break.ties=TRUE) # k smallest elements in a row

Arguments

matr
A numeric matrix
rn
A vector, usually a random number in applications
K
An integer indicating the number of smallest elements to be extracted
break.ties
A logical which indicated if ties are randomly broken. The default is TRUE.

Value

  • The output of rowMaxs.sirt is a list with the elements maxval (rowwise maximum values) and maxind (rowwise maximum indices). The output of rowMins.sirt contains corresponding minimum values with entries minval and minind. The output of rowKSmallest.sirt are two matrices: smallval contains the $K$ smallest values whereas smallind contains the $K$ smallest indices.

Details

The function rowIntervalIndex.sirt searches for all rows n the first index i for which matr(n,i) > rn(n) holds. The function rowKSmallest.sirt extracts the $K$ smallest entries in a matrix row.

See Also

For other matrix functions see the matrixStats package.

Examples

Run this code
#############################################################################
# EXAMPLE 1: a small toy example (I)
#############################################################################
set.seed(789)
N1 <- 10 ; N2 <- 4
M1 <- matrix( runif(N1*N2) , nrow=N1 , ncol=N2)

rowMaxs.sirt(M1)      # rowwise maximum
rowMins.sirt(M1)      # rowwise minimum
rowCumsums.sirt(M1)   # rowwise cumulative sum

# row index for exceeding a certain threshold value  
matr <- M1
matr <- matr / rowSums( matr )
matr <- rowCumsums.sirt( matr )
rn <- runif(N1)	# generate random numbers
rowIntervalIndex.sirt(matr,rn)

# select the two smallest values
rowKSmallest.sirt(matr=M1 , K=2)

Run the code above in your browser using DataLab