as.best: Coerce data unambiguously to numeric or character

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

In some sense, numeric and character are the most general data types. as.best converts to one of these, handling missing or near-missing values systematically.

Usage

1
2
3
4
5
6
7
	## Default S3 method:
as.best(x,prefix='#',na.strings=c('.','NA',''),...)


	## S3 method for class 'data.frame'
as.best(x,...)
	

Arguments

x

object to be coerced

prefix

scalar character value to affix to numeric-like values in a vector containing non-numeric values

na.strings

character vector of values to treat as NA

...

ignored

Details

Data printed at the command prompt can contain many ambiguities. Factors look just like character vectors. Empty strings look just like spaces. Leading or trailing white space can be confused with alignment adjustments. The string value 'NA' can be confused with NA. Character 'TRUE' looks like logical TRUE.

as.best.default coerces its argument to character, strips leading and trailing white space, and coerces na.strings to NA. A numeric vector is returned if all non-missing values can be coerced to numeric. A character vector is returned if any non-missing values cannot be coerced to numeric. If a prefix is supplied (the default) numbers in a mixed vector are prefixed thus; if prefix is length zero, mixed character-numeric gives an error.

The method for data.frame coerces each column in turn, returning either the updated data frame or an error indicating the first problematic column.

Value

an object like x

Author(s)

Tim Bergsma

References

http://metrumrg.googlecode.com

See Also

Examples

1

anniejw6/metrumrg documentation built on May 10, 2019, 11:50 a.m.