-2

really new to coding and trying to figure out how to look at each row, and depending on the values on that row, the one closer in the alphabet gets a 0 while the other one gets a 1.

"Now you will convert the genotype information into a numeric representation that you can analyze mathematically. For each row, you will set the allele closest alphabetically to “A” to be 0 and the other allele to be 1. Thus you will create a matrix of zeros and ones."

I've been going through some R books trying to find a way to do it as well as google searching and cannot find anything.

If anyone has any insight it is much appreciated!

  • Please give us something to work with: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – MichaelChirico Feb 23 '16 at 03:15
  • C C C C C G G G C C C C C C A A A A C C C C A A A A A C C G G T T T T T T T G G G G G – subtlehelp001 Feb 23 '16 at 03:26
  • Give a reproducible example. Even a bioinformatics person has no idea what you are asking, what is in each row? Are you simply trying to go from 'AA' , 'AG' type calls to '00', '01' type calls? – JeremyS Feb 23 '16 at 03:45
  • I tried, but the format came out incorrectly. So each row has either 1 or 2 letters, and it spans a length of 100. So if I have a row filled with 50 A's and 50 G's, I want the A's to become 0 and the G's to become 1. – subtlehelp001 Feb 23 '16 at 04:04

2 Answers2

0

This looks like a homework/assignment question so I'm not going to properly answer it, but hopefully you can get where you're trying to go with the help of

which.min(match(c("Q","G","X"), LETTERS))
[1] 2

and some ifelse syntax.

Jonathan Carroll
  • 3,897
  • 14
  • 34
0

Without anything else to go on, here's a stab in the dark at what you're after:

set.seed(130490)
genes <- data.frame(allele1 = sample(LETTERS), allele2 = sample(LETTERS),
                    stringsAsFactors = FALSE)

genes$allele1_num <- with(genes, allele1 > allele2)
genes$allele2_num <- !genes$allele1_num
MichaelChirico
  • 33,841
  • 14
  • 113
  • 198