mixedData | R Documentation |
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.
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)
x |
A vector containing mixed data (typically |
obj |
An object of class |
fill |
A value to use when no other value is appropriate. See details. |
... |
Additional arguments to be passed to or from methods. |
The class implements just a few methods. The main uses are:
as.numeric
to avoid the warning issued when calling
this method on type character
and the danger of calling it on
type factor
(see Examples).
unique
, which considers all numeric values as
"<Number>"
and hence allows one to quickly identify all
the ‘special’ (non-numeric) values are.
The print
method just prints the character representation but
with quote = FALSE
for readability.
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
.
Benjamin Rich <mail@benjaminrich.net>
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.