[R] Data read as labels

David Winsemius dwinsemius at comcast.net
Mon May 14 19:00:18 CEST 2012


On May 14, 2012, at 11:23 AM, barb wrote:

> Hey David,
>
> thanks for your fast reply, i really appreciate that you answer so  
> many
> posts.
>
> Unfortunately it´s not that easy. Try to operate with the output:
>
> e.g
> file<-read.csv2(tmp,sep=";",skip="5")
> a<-(relevant<-file[,2][1])
> a*5
> # or
> as.numeric(relevant<-file[,2][1])
>
> a is saved in the workspace as a factor and the values i actually  
> need are
> saved as the labels.
> (therefore my subject)

Your subject line asked for "labels". That is not a word that  
represents anything specific in R parlance except perhaps plotting  
function arguments. It you want to prevent the conversion of  
"character" values to factors then you should be using  
stringsAsFactors=FALSE in the read functions.

If you want to convert from factor to character correctly, you could  
also refer to the FAQ. On my machine the section "7.10 How do I  
convert factors to numeric?" is located at:

http://127.0.0.1:13702/doc/manual/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f

You should have a similar copy of the FAQ someplace on your machine.  
It's good to review the "miscellaneous" section a couple of times.

>
> Thank You!
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Data-read-as-labels-tp4629901p4629951.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