Some Matrix Functions
Some matrix functions which are written in Rcpp for speed reasons.
rowMaxs.sirt(matr) # rowwise maximum rowMins.sirt(matr) # rowwise minimum rowCumsums.sirt(matr) # rowwise cumulative sum colCumsums.sirt(matr) # columnwise 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 rowKSmallest2.sirt(matr, K )
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 indicates if ties are randomly
broken. The default is |
The function rowIntervalIndex.sirt
searches for all rows n
the first index i
for which matr(n,i) > rn(n)
holds.
The functions rowKSmallest.sirt
and rowKSmallest2.sirt
extract the K smallest entries in a matrix row. For small
numbers of K the function rowKSmallest2.sirt
is
the faster one.
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.
Alexander Robitzsch
The Rcpp code for rowCumsums.sirt
is copied from code of
Romain Francois
(https://lists.r-forge.r-project.org/pipermail/rcpp-devel/2010-October/001198.html).
For other matrix functions see the matrixStats package.
############################################################################# # EXAMPLE 1: a small toy example (I) ############################################################################# set.seed(789) N1 <- 10 ; N2 <- 4 M1 <- round( matrix( runif(N1*N2), nrow=N1, ncol=N2), 1 ) 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 <- sirt::rowCumsums.sirt( matr ) rn <- runif(N1) # generate random numbers rowIntervalIndex.sirt(matr,rn) # select the two smallest values rowKSmallest.sirt(matr=M1, K=2) rowKSmallest2.sirt(matr=M1, K=2)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.