Skip to content
Prev 76131 / 398502 Next

Converting characters to numbers in data frames

Try:

NAMES=c("NRes.1.2.", "NRes.1.3.", "NRes.1.4.", "NRes.1.5.", "NRes.1.6.")
pattern<-"NRes\.([0-9]*)\.([0-9]*)\."
data.frame(x=sub(pattern,"\\1",NAMES),y=sub(pattern,"\\2",NAMES))

@
output-start
Thu Aug 25 14:08:50 2005
  x y
1 1 2
2 1 3
3 1 4
4 1 5
5 1 6
output-end

Peter Wolf
Anon. wrote: