swh:1:snp:0f920b1e114986636ba2e45b5c1a83473fb6cf12
Raw File
Tip revision: 3e594f8fd8b56d6c609b1857ad9b41d057235295 authored by Lars Kotthoff on 16 February 2021, 17:20:03 UTC
version 0.33
Tip revision: 3e594f8
cutoff.R
cutoff.k <- function(attrs, k) {
	if(dim(attrs)[1] == 0)
		return(character(0))
	if(k < 1)
		stop("k too small")
	if(k > dim(attrs)[1])
		k = dim(attrs)[1]
	sorted_names = rownames(attrs)[do.call(order, c(attrs, decreasing = TRUE))]
	return(sorted_names[1:k])
}

cutoff.k.percent <- function(attrs, k) {
	if(dim(attrs)[1] == 0)
		return(character(0))
	if(k <= 0)
		stop("k too small")
	if(k > 1) {
		warning("Assumed k=1")
		k = 1
	}
	sorted_names = rownames(attrs)[do.call(order, c(attrs, decreasing = TRUE))]
	return(sorted_names[1:round((k * length(sorted_names)))])
}

cutoff.biggest.diff <- function(attrs) {
	if(dim(attrs)[1] == 0)
		return(character(0))
	else if(dim(attrs)[1] == 1)
		return(dimnames(attrs)[[1]])
	
	perm = order(attrs[,1], decreasing = TRUE)
	attrs = attrs[perm, , drop = FALSE]
	
	intervals = sapply(1:(dim(attrs)[1] - 1), function(idx) {
			attrs[idx, 1] - attrs[idx + 1, 1]
		})
	
	return(dimnames(attrs)[[1]][1:(which.max(intervals))])
}
back to top