Learn R Programming

wrMisc (version 2.1.0)

rowGrpNA: Count Number Of NAs Per Row And Group Of Columns

Description

This functions allows easy counting of the number of NAs per row in data organized in multiple sub-groups as columns.

Usage

rowGrpNA(
  mat,
  grp = NULL,
  initColOrder = TRUE,
  mode = "simple",
  digits = 2,
  silent = FALSE,
  debug = FALSE,
  callFrom = NULL
)

Value

This function returns typically a matrix (or numeric vector if all grouping falls in a single class or charcter-vector if all groups get collapsed in single chain of characters) with number of NAs per group

Arguments

mat

(matrix, data.frame, list or 'MArrayLM') data to count the number of NAs; in case of furnishing a list or MArrayLM-class a list-element called 'isNA' will be used as mat or all NA positions of list-element called 'raw'

grp

(character or factor) defining which columns should be grouped (considered as replicates). If grp is not provided and mat is list or 'MArrayLM'-class containg a list-element 'setup' (as produced with testing from package wrProteo the group-association will be taken from there

initColOrder

(logical) ifFALSE the columns may be in (alphabetically) sorted order

mode

(character) switch between different types of output : - mode="simple" will return simply the number of NAs per line and group as integer - mode="simpleCollapse" will collapse all columns into single chain of characters with the number of NAs per line and group (as character) - mode="complete" will return number of NAs per line and group accompanied by the number of columns associated with the very group (as character) - mode="completeCollapse" will collapse all columns into single chain of characters with the number of NAs per line and group accompanied by the number of columns associated with the very group (as character) - mode="ratio" will return the ratio of NAs per line and group (as numeric) - mode="ratioCollapse" will collapse all columns into single chain of characters with the ratio of NAs per line and group(as character)

digits

(integer, length=1) number of decimal digits from rounding (when ratios are calculated)

silent

(logical) suppress messages

debug

(logical) additional messages for debugging

callFrom

(character) allows easier tracking of messages produced

Details

First of all, this function allows counting the number of NAs per line and sub-group of columns as defined by argument grp. Furthermore, the counting can be expressed relative to the size of the sub-groups, either as ratio or by giving the NA-count using mode="ratio" and the size of the sub-group using mode="complete" . Finally, all results may get collaped in as single (character) vector, however, the names of the groups do not get conserved.

See Also

rowGrpMeans, rowSds, colSums

Examples

Run this code
mat2 <- matrix(1, nrow=200, ncol=40)
mat2[sample.int(prod(dim(mat2)), nrow(mat2), replace=FALSE)] <- NA
grp2 <- as.factor(sample.int(n=8, size=ncol(mat2), replace=TRUE))
  table(grp2)
## overal number of NAs per row
rowSums(is.na(mat2)) 

## number of NAs per row and group
head(rowGrpNA(mat2, grp2))
head(rowGrpNA(mat2, grp2, mode="simple"))
head(rowGrpNA(mat2, grp2, mode="complete"))

## mimick output from testing from package wrProteo
dat1 <- list(isNA =mat2, setup=list(grp=grp2))
head(rowGrpNA(dat1, mode="simple"))
head(rowGrpNA(dat1, mode="complete"))
head(rowGrpNA(dat1, mode="ratioCollapse"))

Run the code above in your browser using DataLab