[R] Data read as labels
David Winsemius
dwinsemius at comcast.net
Tue May 15 19:38:39 CEST 2012
On May 15, 2012, at 11:13 AM, barb wrote:
> Hey David,
>
> i tried all this - it doesn´t work :(
Sadder and less informative words were never written!
Learn to express in natural language or in code what you were
expecting rather than use the phrase "doesn't work" which can mean one
of an almost infinite sources of programming failure.
>
> file<-read.csv2(tmp,sep=";",skip="5") # or
> file<-read.csv2(tmp,sep=";",skip="5",stringsAsFactors=FALSE)a<-
> (relevant<-file[,2])
> clean <- as.numeric(levels(a))[as.integer(a)]
> clean<-as.numeric(as.character(a))
>
When I do that, I get a series of comma-separated digit values inside
strings (because the default setting for the decimal separator is
period = Punct auf Deutsch if I remember my lessons from 40 years ago,
"." and not Komma ) so at the end I get:
....
[490] "94801,00"
[491] "85013,00"
[492] "85982,00"
[493] "91213,00"
[494] "98912,00"
[495] "Bemerkung: "
[496] "Methodik: Ab Januar 1993 einschl. der Zuschätzungen für
nichtmelde- pflichtigen Außenhandel, die bis Dezember 1992 in den
Ergänzungen zum Außenhandel enthalten sind."
So what is "not working" and what would be "success"? Is this
successful?
> aconv <- sub("\\,", ".", a)
> str(as.numeric(aconv))
num [1:496] 10716 12897 11330 10930 11485 ...
Warning message:
In str(as.numeric(aconv)) : NAs introduced by coercion
> as.numeric(aconv[480:494])
[1] 78645.63 84067.37 98180.37 84252.25 92003.35 88139.63 85664.93
85138.00 94960.00
[10] 89170.00 94801.00 85013.00 85982.00 91213.00 98912.00
>
> i often use noquote and strsplit and then convert data, but i never
> dealed
> with that kind of data
> and it drives me crazy =)
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Data-read-as-labels-tp4629901p4630112.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list