9
Given a data.frame containing columns of only strings (no factors), some of which should remain strings, some of which are integers, and some of which are doubles, how can I guess the most appropriate storage mode to which to convert the strings?
fixDf <- data.frame(isChar=c("A", "B", "C"),
isDouble=c("0.01", "0.02", "0.03"),
isInteger=c("1", "2", "3"), stringsAsFactors=FALSE)
I am wondering if there is an easy way to determine that the following needs to be done, and then to do it:
mode(fixDf[, "isDouble"]) <- "double"
mode(fixDf[, "isInteger"]) <- "integer"
Ideally, where errors are encountered a function to handle this would leave the data in its string form.