[R] change col types of a df/tbl_df
Giorgio Garziano
giorgio.garziano at ericsson.com
Thu Dec 10 13:47:35 CET 2015
my_convert <- function(col) {
v <- grep("[0-9]{2}.[0-9]{2}.[0-9]{4}", col);
w <- grep("[0-9]+,[0-9]+", col)
col2 <- col
if (length(v) == length(col)){
col2 <- as.Date(col, format="%d.%m.%y")
} else if (length(w) == length(col)) {
col2 <- as.numeric(gsub(",", "", col))
}
col2
}
myDf <- as.data.frame(lapply(myDf, my_convert), stringsAsFactors = FALSE)
--
GG
[[alternative HTML version deleted]]
More information about the R-help
mailing list