[R] help with replacing all comma in a data frame with a dot

John Kane jrkrideau at yahoo.ca
Wed Jan 23 20:28:38 CET 2008


I think this will do it. 
 
mysub <- function(x) {sub(",",".",x)}
mydata <- (apply(kk, 2, mysub ))
kk1 <- data.frame(apply(mydata, 2, as.numeric))
 
--- Tom Cohen <tom.cohen78 at yahoo.se> wrote:

> Dear list,
>    
>   I have imported a spss data file in R, where a
> comma is used to separate the decimal numbers, e.g.
> 3,567 instead of 3.567 as in R. How can I replace
> the comma with a dot for all values in the data
> frame
>    
>   >kk
>                             a            b     c  d 
>        e    f
> 1  ,0925199910320613  82523  8  ,855  ,803  ,69
> 2   ,278314161923372  91657 26 1,285 1,032 ,823
> 3   ,278314161923372  91657 26 1,285 1,032 ,823
> 4   ,278314161923372  91657 26 1,285 1,032 ,823
> 5   ,278314161923372  91657 26 1,285 1,032 ,823
> 6   ,278314161923372  91657 26 1,285 1,032 ,823
> 7   ,203740581833404  72026 94  ,479    ,3 ,061
> 8   ,243694169416943  23684 77 1,375  ,437 ,054
> 9                 ,3  21857 86  ,829  ,315 ,029
> 10                ,6 111569 93  ,764    ,4 ,076
> 11                ,6 111569 93  ,764    ,4 ,076
> 12                ,6 111569 93  ,764    ,4 ,076
> 13        ,419788431  35744 95   ,44  ,298 ,076
> 14        ,419788431  35744 95   ,44  ,298 ,076
> 16         ,39266161  29098 90  ,361  ,256 ,076
> 17         ,39266161  29098 90  ,361  ,256 ,076
> 18        ,691736472  40135 85  ,864  ,284  ,09
> 19        ,691736472  40135 85  ,864  ,284  ,09
> 20        ,442407817  48673 86   ,44  ,279 ,088
> 24 ,0925199910320613  22482 64  ,104  ,082 ,054
> 
>   Thanks in advance,
>   Tom
> 
>        
> ---------------------------------
> S�k efter k�rleken! 
> 
> 	[[alternative HTML version deleted]]
> 
> > ______________________________________________
> R-help at r-project.org mailing list
> 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.
> 



      Looking for the perfect gift? Give the gift of Flickr!



More information about the R-help mailing list