Re: [R] Factor to variable

2010-06-05 Thread Phil Spector

Try

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

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Sat, 5 Jun 2010, bjlwilkin...@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@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@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.


Re: [R] Factor to variable

2010-06-05 Thread Pete B

Hi

How about ...

# Data
lines = 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

# Create Dataframe
DF - read.table(textConnection(lines), header = TRUE, check.names = FALSE)

# Create Numeric Variable 
DF$Col5 = as.numeric(sub(X,,DF$Col3))

HTH

Pete
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Factor-to-variable-tp2244337p2244384.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.