[R] decimal separator from comma to dot

mbressan at arpa.veneto.it mbressan at arpa.veneto.it
Fri Aug 9 21:35:41 CEST 2013


This is my reproducible example

df<-structure(list(IDANT = c(37837L, 37838L, 37839L, 37840L, 37841L, 
37842L, 37843L, 40720L, 40721L, 40722L), N_TX = c(6L, 6L, 6L, 
4L, 1L, 1L, 1L, 2L, 2L, 1L), TILT = c(0L, 0L, 0L, 0L, 6L, 6L, 
6L, 0L, 0L, 0L), DIREZIONE = c(50L, 220L, 110L, 50L, 220L, 110L, 
50L, 170L, 70L, 270L), DATA_INI = structure(c(2L, 2L, 2L, 2L, 
2L, 2L, 2L, 1L, 1L, 1L), .Label = c("20/10/2004", "29/08/2002" 
), class = "factor"), POT_TX = structure(c(4L, 4L, 4L, 3L, 2L, 
2L, 2L, 1L, 1L, 1L), .Label = c("10", "11,5", "4", "8"), class =
"factor")), .Names = c("IDANT", 
"N_TX", "TILT", "DIREZIONE", "DATA_INI", "POT_TX"), row.names = c(NA, 
10L), class = "data.frame") 

from david winsemius reply (quite annoyed by me, sorry for that!)
http://r.789695.n4.nabble.com/decimal-separator-from-comma-to-dot-td4673414.html#a4673461
and from faq 7.10
I learnt this is the correct way to perform the conversion from factor to
number for a single variable

df$POT_TX <- as.numeric(as.character( sub(",", ".", df$POT_TX )))

but what about the case of more than one column (variable) in a data frame?

I hope now my question is fine with the rules of this mailing list

thank you all for the patiente
I'm learning a lot


max



More information about the R-help mailing list