I am reading in a csv file into R that looks like this:
3,3
3,2
3,3
3,3
3,3
3,3
2,3
1,2
2,2
3,3
I want to assign a number to each of the 9 unique possibilities that my data can be (3 and 3 is 9, 3 and 2 is 8, 2 and 3 is 6, etc.). I have been trying do design a nested if statement that will evaluate each row, assign a number in a third column, and do this for each row in the data set. I believe this can be done with the apply function, but I am having trouble getting the if statement to work within the apply function. The two columns both have possible values of 1,2, or 3. This is my code thus far, just trying to assign a 9 to to 3/3 columns and 0 to everything else:
#RScript for haplotype analysis
#remove(list=ls())
options(stringsAsFactors=FALSE)
setwd("C:/Documents and Settings/ColumbiaPC/Desktop")
#read in comma-delimited, ID-matched genotype data
OXT <- read.csv("OXTRhaplotype.csv")
colnames(OXT)<- c("OXT1","OXT2")
OXT$HAP <- apply(OXT, 1, function(x) if(x[1]=="3"&&x[2]=="3")x[3]=="9" else 0))
Thanks for any help in advance.