Hi! I am trying to produce a table for a haplotype network with the library pegas. However, in the very step of producing the table a keep getting this error and I am not very sure where is the mistake:
Error in table(hap = ind, pop = attr(dna, "dimnames")[[1]][values]) :
all arguments must have the same length
library(ape)
library(pegas)
data<-read.FASTA("C:\path\to\fasta\file.fasta")
checkAlignment(data)
datahaplo<-haplotype(data)
datahaplo
datahaplo<-sort(datahaplo, what = "labels")
dataNet<-haploNet(datahaplo)
countHap <- function(hap = h, dna = x){with(stack(setNames(attr(hap, "index"), rownames(hap))), table(hap=ind, pop=attr(dna, "dimnames")[[1]][values]))}
write.table(countHap(datahaplo, data), file=file.txt, sep="\t", quote=FALSE)
Thank you very much for your help!