Re: [R] Dataframe manipulation

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Tue, 4 Dec 2007 15:10:17 +0100

try this (also look at R-FAQ 7.10):

sapply(df, function (x) as.numeric(levels(x))[as.integer(x)])

I hope it helps.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


> Hello,
>
> can anybody help me with this problem?
> I have a dataframe, which contains its values as factors though I
> have numbers
> but it was read as factors with "scan". Now I would like to convert
> these
> columns (multiple) to a numeric format.
>
>
> # this example creates a similar situation
>
> testdata <- as.factor(c("1.1",NA,"2.3","5.5"))
> testdata2 <- as.factor(c("1.7","4.3","8.5",10.0))
>
> df <- data.frame(testdata, testdata2)
>
> what do I have to do to get the same datafram but with numeric
> values???
>
> Antje
>
> ______________________________________________
> 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.
>

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



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. Received on Tue 04 Dec 2007 - 14:13:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 04 Dec 2007 - 16:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.