Description Usage Arguments Value Author(s) See Also Examples
Remove columns containing missing values from a data frame or a matrix
1 2 |
dat |
A data frame or a matrix |
rows |
rows to include in evaluating the missing values of columns, can be a list of vectors to specify row subsets |
tolerance |
Number of non-NA cells that are "tolerated", can be a list corresponding to |
cumulate |
if |
remove |
if |
verbose |
if |
depends on option remove
Martin Hecht
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # example matrix
(mat <- matrix(c(1,1,1,1,1,1, 1,1,1,1,1,NA, 1,1,1,1,NA,NA, 1,1,1,NA,NA,NA,
1,1,NA,NA,NA,NA, 1,NA,NA,NA,NA,NA, NA,NA,NA,NA,NA,NA), ncol=7))
# remove column with entirely NA (column 7)
rmNAcols(mat, verbose = TRUE)
# remove column with NA on rows 3, 4, 5 (columns 5, 6, 7)
rmNAcols(mat, c(3,4,5), verbose = TRUE)
rmNAcols(mat, c(-1,-2,-6), verbose = TRUE)
# tolerance=1 , 1 non-NA is permitted (columns 6 and 7)
rmNAcols(mat, tolerance=1, verbose = TRUE)
# tolerance=6 , 6 non-NA are permitted (all columns are removed)
rmNAcols(mat, tolerance=6, verbose = TRUE)
# do not cumulate / exact tolerance (column 1)
rmNAcols(mat, tolerance=6, cumulate=FALSE, verbose = TRUE)
# two subsets of rows
rmNAcols(mat, rows = list(c(1, 2), c(4, 5)), verbose = TRUE)
# two subsets of rows with different tolerance
rmNAcols(mat, rows = list( 1, c(2, 3, 4, 5)), tolerance = list(0, 1), verbose = TRUE)
# identify cols, no deletion
rmNAcols(mat, rows = list(c(1, 2), c(3, 4, 5)), tolerance = list(0, 1), remove = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.