Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

colnth

Column and row-wise nth smallest value of a matrix/vector


Description

Column and row-wise nth smallest value of a matrix/vector.

Usage

colnth(x,elems, num.of.nths = 1,descending = FALSE,na.rm = FALSE,
	index.return = FALSE, parallel = FALSE)
rownth(x,elems, num.of.nths = 1,descending = FALSE,na.rm = FALSE,
	index.return = FALSE, parallel = FALSE)
nth(x, k, num.of.nths = 1,descending = FALSE,index.return = FALSE,na.rm = FALSE)

Arguments

x

A matrix with the data.

elems

An integer vector with the kth smallest number to be returned for each column/row.

k

The kth smallest/biggest number to be returned.

num.of.nths

The number of the returned nths. By default is 1. Not use with argument parallel, for now.

descending

A boolean value (TRUE/FALSE) for descending order (biggest number). By default is ascending (smallest number).

index.return

Return the index of the kth smallest/biggest number.

parallel

Do you want to do it in parallel in C++? TRUE or FALSE only for col-row wise.

na.rm

TRUE or FAlSE for remove NAs if exists. Only for function "nth".

Details

The functions is written in C++ in order to be as fast as possible.

Value

For "colnth" , "rownth": A vector with the column/row nth

For "nth": The nth value.

Author(s)

Manos Papadakis <papadakm95@gmail.com>

R implementation and documentation: Michail Tsagris <mtsagris@yahoo.gr> and Manos Papadakis <papadakm95@gmail.com>.

See Also

Median, colMedians, colMeans (buit-in R function)

Examples

x <- matrix( rnorm(100 * 100), ncol = 100 )
elems <- sample(1:100,100,TRUE)
system.time( colnth(x,elems) )
system.time( rownth(x,elems) )
x <- rnorm(1000)
nth(x, 500)
sort(x)[500]

x<-elems<-NULL

Rfast

A Collection of Efficient and Extremely Fast R Functions

v2.0.1
GPL (>= 2.0)
Authors
Manos Papadakis, Michail Tsagris, Marios Dimitriadis, Stefanos Fafalios, Ioannis Tsamardinos, Matteo Fasiolo, Giorgos Borboudakis, John Burkardt, Changliang Zou, Kleanthi Lakiotaki and Christina Chatzipantsiou.
Initial release
2020-09-13

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.