[R] recoding genetic information using gsub

Kate Ignatius kate.ignatius at gmail.com
Fri Dec 5 20:24:07 CET 2014


I have genetic information for several thousand individuals:

A/T
T/G
C/G  etc

For some individuals there are some genotypes that are like this:  A/,
C/, T/, G/ or even just / which represents missing and I want to
change these to the following:

A/ A/.
C/ C/.
G/ G/.
T/ T/.
/ ./.
/A ./A
/C ./C
/G ./G
/T ./T

I've tried to use gsub with a command like the following:

gsub("A/","[A/.]", GT[,6])

but if genotypes arent like the above, the command will change it to
look something like:

A/.T
T/.G
C/.G

Is there anyway to be more specific in gsub?

Thanks!



More information about the R-help mailing list