keep_finite: Keep finite values

Description Usage Arguments Value Examples

View source: R/keep_finite.R

Description

Remove NAs codeNaNs and codeInfs from data

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
keep_finite(x, ...)

## Default S3 method:
keep_finite(x, ...)

## S3 method for class 'matrix'
keep_finite(x, margin = 1, keep = c("any",
  "complete"), ...)

## S3 method for class 'data.frame'
keep_finite(x, margin = 1, keep = c("any",
  "complete"), ...)

Arguments

x

a vector or matrix

...

further arguments passed to methods

margin

if x is matrix, which margin to keep finites by

keep

if x is matrix, keep rows/columns with any finite values, or keep only complete rows/columns.

Value

If x is a matrix and margin is 1 or 2, a matrix is returned. Else a vector.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
m1 <- matrix(c(10, 20, 30, 43,
               10, NA, 32, 50,
               NA, NA, NA, NA,
               13, 22, 70, 81,
               NA, 29, NA, 41), 5, byrow=TRUE,
               dimnames=list(letters[1:5], LETTERS[1:4]))

keep_finite(m1) 
matplot(keep_finite(apply(m1, 2, sort, na.last=TRUE)), type="l")

m1[complete.cases(m1),]
keep_finite(m1, 1, "c") #same
keep_finite(m1, 2, "complete") #no complete columns

m1.df <- as.data.frame(t(m1))
keep_finite(m1.df, 2, "complete")

AkselA/R-ymse documentation built on March 21, 2020, 9:52 a.m.