[R] help with replacing all comma in a data frame with a dot
Henrique Dallazuanna
wwwhsd at gmail.com
Wed Jan 23 17:00:03 CET 2008
apply(apply(df, 2, gsub, patt=",", replace="."), 2, as.numeric)
or you can read the data file with read.table using dec argument:
df <- read.table('clipboard', dec=",", header=T, row.names=1)
On 23/01/2008, 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.
>
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
More information about the R-help
mailing list