Learn R Programming

dmm (version 2.1-3)

chartodec: 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

Value

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

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.

See Also

Function read.fwf()

Examples

Run this code
# NOT RUN {
library(dmm)
tmp <- c("1","2","3",NA)
ntmp <- chartodec(tmp,1)
str(ntmp)
rm(tmp)
rm(ntmp)
# }

Run the code above in your browser using DataLab