Re: [R] Factor to variable

From: Pete B <>
Date: Sat, 05 Jun 2010 09:51:24 -0700 (PDT)


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:
Sent from the R help mailing list archive at

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 05 Jun 2010 - 16:58:05 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 - 17:20:28 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive