1. The first converts to numeric and manipulates that:
[37] "0.30" " ?NA" "0.30" "0.30" "0.30" "0.30" " ?NA" " ?NA" "0.35"
"NA" "0.35" "0.30"
[49] "0.30" "0.40" " ?NA" "0.40" "0.30" " ?NA" "0.30" "0.30" "0.30"
"0.30" "0.45" "0.30"
[61] "0.30" "0.30" "0.30" "0.50" "0.30" "0.30" "0.45" "0.30"
How do I output the number to the left of "." to variable X and the
two numbers to the right of "." to variable Y?
FICB[,"x"] <- substr(FICB[,"temp2"],1,1)
Works, but
FICB[,"y"] <- substr(FICB[,"temp2"],3,2)
only returns "". temp is class character.
That will happen when stop < start, try "...,3,4)"!
Alternatively sub("^[0-9]*\\.", "", ...) and sub("\\.[0-9]*$", "", ...)
should do the trick slightly more generally.
sub("^[0-9]*\\.", "", "0.30")
sub("\\.[0-9]*$", "", "0.30")
[1] "0"
(and in either case, don't forget to get rid of the ".*NA.*" elements)
--
? O__ ?---- Peter Dalgaard ? ? ? ? ? ? ?ster Farimagsgade 5, Entr.B
?c/ /'_ --- Dept. of Biostatistics ? ? PO Box 2099, 1014 Cph. K
?(*) \(*) -- University of Copenhagen ? Denmark ? ? ?Ph: ?(+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) ? ? ? ? ? ? ?FAX: (+45) 35327907