[R] using read.csv2()

Rainer M Krug Rainer at krugs.de
Thu Sep 29 11:07:46 CEST 2016


Voirin Pascale <Pascale.Voirin at hefr.ch> writes:

> Hello,
>
> I have a problem with the variable type defined by reading a csv file with read.csv2.
>
> Here is a test file saved as < test.csv > :
> var1;var2;var3
> TI;1995;4.5
> VD;1990;4.8
> FR;1994;3.9
> VS;1993;5.1
> FR;1995;4.7
> FR;1992;5.8
>
> That  I read in R with :
> read.csv2("test.csv")->don;don
> don$var3
> ## [1] 4.5 4.8 3.9 5.1 4.7 5.8
> ## Levels: 3.9 4.5 4.7 4.8 5.1 5.8
>
> as.double(don$var3)
> ## [1] 2 4 1 5 3 6
>
> Why is it by default a <levels> type ? And how can I get  the decimal value for var3

You very likely have a character in your column named var3. Just check
your Levels after the import, and you should see it.

Cheers,

Rainer

>
> Thanks a lot for your answer.
> With my best regards,
>
> Pascale Voirin
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.

-- 
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 454 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20160929/ecab5bc2/attachment.bin>


More information about the R-help mailing list