mixedData: A Class for Mixed Character and Numeric Data

Description Usage Arguments Details Value Author(s) Examples

Description

The purpose of this class is to represent data that is essentially numeric, but also included some ‘special’ values that are non-numeric and hence the object cannot cannot be represented by a standard numeric class. A typical example would be an assay result that used a symbol like "BQL<(1.00)" to represent left-censored values.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
mixedData(x)
## S3 method for class 'mixedData'
unique(obj)
## S3 method for class 'mixedData'
as.character(obj)
## S3 method for class 'mixedData'
as.double(obj, fill = NA)
## S3 method for class 'mixedData'
as.data.frame(obj, ...)
## S3 method for class 'mixedData'
print(obj)

Arguments

x

A vector containing mixed data (typically character or factor).

obj

An object of class mixedData.

fill

A value to use when no other value is appropriate. See details.

...

Additional arguments to be passed to or from methods.

Details

The class implements just a few methods. The main uses are:

The print method just prints the character representation but with quote = FALSE for readability.

Value

mixedData returns a new object of class mixedData.

The methods return what one would expect: as.charater, unique and print return character, as.double returns numeric.

Author(s)

Ben Rich <benjamin.rich@certara.com>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Generate a vector with approx. 5% left-censoring:
set.seed(123)
x <- rexp(350, 0.05129329)
x <- ifelse(x < 10, "BQL<(1.00)", as.character(signif(x, 4)))
# Another 'special' result, 'quantity not sufficient':
x[129] <- "QNS"
x <- factor(x)

unique(x)  # Not very useful

# Warning! not the desired result when x is a factor:
as.numeric(x)

# This works, but you get a warning:
as.numeric(as.character(x))

y <- mixedData(x)
unique(y)
print(y)
as.numeric(y)
as.character(y)

benjaminrich/PCSmisc documentation built on May 24, 2019, 5:02 a.m.