I have large set will a number of variables:
set.seed (14)
pool = sample (c("AA","AB", "BB"), 100, replace = T)
mydf <- data.frame (M1= pool[1:10], M2= pool[11:20],
M3= pool[21:30], M4= pool[31:40], M5= pool[41:50],
M6= pool[51:60], M7= pool[61:70], M8 = pool[71:80],
M9 = pool[81:90], M10 = pool[91:100])
Need to install the package “hapassoc”, if previously installed.
install.packages(“hapassoc”)
> library(hapassoc)
> example1.haplos <- pre.hapassoc(mydf, numSNPs = 3, allelic= F)
Haplotypes will be based on the following SNPs (genotypic format):
M8, M9, M10
Remaining variables are:
M1, M2, M3, M4, M5, M6, M7
It is taking last 3 variables in group. But 1 want apply this function by breaking data into smaller pieces by group –
M1, M2, M3 group 1
M4, M5 group 2
M6, M7, M8 group 3
M9, M10 group 4
Thus numSNPs would be represented by the following vector:
nsp <- c(3, 2, 3, 2)
I want to preserve the $haploMat for each group
example1.haplos$haploMat
haplo1 haplo2
1 hBBA hBAB
3 hAAB hABB
4 hABA hABA
6 hAAA hBBA
7 hAAA hAAA
8 hBBA hBBB
9 hABB hBBB
10 hABA hBAB
12 hAAA hBBB
13 hAAB hBBA
14 hABA hABA
15 hAAB hBAB
The final output have eight columns group1.haplo1, goup1.haplo2, group2.haplo1, group2.haplo2, group3.haplo1, group4.haplo1, group4.haplo2.
How can I achieve this ?
Is this what you’re after? (specify the column numbers of the groups as elements of the list assigned to
grps). You’ll need thereshape2package installed. You could do something similar withrbind.fill()from theplyrpackage.RESULT