I have a csv file that has genotype counts in three columns. I am using read.table() to import the csv, and using another variable to extract data from those columns specifically:
Example of data:
SNP, Allele, CC, CT, TT
1, .329, 12, 3, 4
2, .231, 3, 2, 6
3, .214, 5, 4, 5
Code:
library(HardyWeinberg)
x = read.table("SNPs.csv", header=T, sep = ",")
y = c(x$CC, x$CT, x$TT)
HW.test = HWExact(y, verbose=TRUE)
The problem is that HW.test is reading down the column instead of across the row, so using the above data, it would calculate HWE for 12, 3, and 5, rather than 12, 3, 4.
How do I ensure that it gets read horizontally?
Looking at
?HWExact, it appears that it’s only designed to take a vector of length 3 (i.e., make calculations for one set of HW genotypes.It also looks like
?HWExactMatis designed for what you want to do. InHWExactMat, the first argument is a matrix of 3 columns (and the example displayed looks like what you’re trying to do). So try: