[R] change col types of a df/tbl_df

arnaud gaboury arnaud.gaboury at gmail.com
Thu Dec 10 13:52:23 CET 2015


On Thu, Dec 10, 2015 at 1:47 PM, Giorgio Garziano <
giorgio.garziano at ericsson.com> wrote:

> 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)
>
> Sounds good. I will give a try,
Thank you

> --
> GG
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 

google.com/+arnaudgabourygabx
<https://plus.google.com/_/notifications/emlink?emr=05814804238976922326&emid=CKiv-v6PvboCFcfoQgod6msAAA&path=%2F116159236040461325607%2Fop%2Fu&dt=1383086841306&ub=50>

	[[alternative HTML version deleted]]



More information about the R-help mailing list