Re: [R] Factor to variable

From: Phil Spector <spector_at_stat.berkeley.edu>
Date: Sat, 05 Jun 2010 07:38:31 -0700 (PDT)

Try

   z$Col3 = as.numeric(sub('^X','',as.character(z$Col3)))

On Sat, 5 Jun 2010, bjlwilkinson_at_gmail.com wrote:

> I have a data frame called z that includes four columns:
>
> Col1 Col2 Col3 Col4
> Text1 Text2 X0.1 5
> Text1 Text2 X0.2 10
> Text1 Text2 X0.3 15
> Text1 Text3 X0.1 5
> Text1 Text3 X0.2 10
> Text1 Text3 X0.3 15
>
> I am trying to convert the 3rd column to the numeric value excluding the X so that I can produce a lattice plot.
>
> I have tried a number of approaches including z$Col3[z$Col3=="X0.1"]="0.1" as a first step but get an error: invalid factor level NAs generated.
>
>
> Sent from my BlackBerry® wireless device
> ______________________________________________
> 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.
>



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 Sat 05 Jun 2010 - 14:41:58 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 Sat 05 Jun 2010 - 14:50:26 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.

list of date sections of archive