chartodec {dmm} | R Documentation |
A vector of numbers encoded as character strings without a decimal point is converted to numbers with a decimal point in a given position
chartodec(cvec, ndec)
cvec |
A vector of type character. |
ndec |
An integer giving the number of digits to follow the implied decimal point |
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.
A vector of numerical values with a decimal point inserted as per argument ndec
Neville Jackson
Function read.fwf()
library(dmm)
tmp <- c("1","2","3",NA)
ntmp <- chartodec(tmp,1)
str(ntmp)
rm(tmp)
rm(ntmp)