chartodec {dmm}R Documentation

Convert a vector from character to decimal numbers

Description

A vector of numbers encoded as character strings without a decimal point is converted to numbers with a decimal point in a given position

Usage

chartodec(cvec, ndec)

Arguments

cvec

A vector of type character.

ndec

An integer giving the number of digits to follow the implied decimal point

Details

It is a common problem when reading a table of fixed width formatted data into a dataframe using function read.fwf() for the dataframe columns to end up of type character with no decimal point. If these columns are actually meant to be decimal numbers with an implied decimal point in a fixed position, they can be converted to numeric with this function.

Value

A vector of numerical values with a decimal point inserted as per argument ndec

Author(s)

Neville Jackson

See Also

Function read.fwf()

Examples


library(dmm)
tmp <- c("1","2","3",NA)
ntmp <- chartodec(tmp,1)
str(ntmp)
rm(tmp)
rm(ntmp)

[Package dmm version 2.1-10 Index]