[R] changing "," to "." in data.frame
Berend Hasselman
bhh at xs4all.nl
Wed Oct 11 09:58:41 CEST 2017
> On 11 Oct 2017, at 09:45, Troels Ring <tring at gvdnet.dk> wrote:
>
> Dear friends - I have a data.frame with "," instead of "." and found the discussion
>
> http://r.789695.n4.nabble.com/How-to-replace-all-commas-with-semicolon-in-a-string-tt4721187.html#a4721192
>
> so copying the code of Ulrik(I hope:-)) I tried
>
> (making some data)
>
> AX <- data.frame(a=chartr(".",",",rnorm(5)),b=chartr(".",",",rnorm(5)),c=rnorm(5))
>
> library(plyr)
>
> adply(AX, 2, function(x){
> if(!is.numeric(x[[1]]){
> gsub(",", ".", x[[1]])
> }else{
> x[[1]]
> }
> })
>
> and got the unwelcome error
>
> Error: unexpected '{' in:
> "adply(AX, 2, function(x){
> if(!is.numeric(x[[1]]){"
>
Missing ) in if(!is.numeric(x[[1]]){
It should be
if(!is.numeric(x[[1]]) ){
Berend Hasselman
> Here is:
>
> > sessionInfo()
> R version 3.4.1 (2017-06-30)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 7 x64 (build 7601) Service Pack 1
>
> Matrix products: default
>
> locale:
> [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252
> [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C
> [5] LC_TIME=Danish_Denmark.1252
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> other attached packages:
> [1] plyr_1.8.4 TinnRcom_1.0.20 formatR_1.5 svSocket_0.9-57
>
> loaded via a namespace (and not attached):
> [1] compiler_3.4.1 tools_3.4.1 svMisc_0.9-70 Rcpp_0.12.13 tcltk_3.4.1
>
> All best wishes
>
> Troels Ring, Aalborg, Denmark
>
> ______________________________________________
> 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.
More information about the R-help
mailing list