Can you try the following function.
########################################################################
# testing percentage of correct genotypes between two datasets #########
########################################################################
genotypes_2_datasets <- function(x,y){
cat("Testing percentage of correct genotypes between two datasets\n")
x <- gl.keep.ind(x, ind.list = indNames(y),verbose = 0)
x <- gl.filter.callrate(x, threshold = 1,verbose=0)
x <- gl.filter.monomorphs(x,verbose = 0)
y <- gl.filter.callrate(y, threshold = 1,verbose = 0)
t2 <- which(x$loc.names %in% y$loc.names)
t3 <- which(y$loc.names %in% x$loc.names)
x <- gl.keep.loc(x, loc.list = locNames(x)[t2],verbose = 0)
x <- x[, order(x$loc.names)]
x <- x[order(indNames(x)), ]
y <- gl.keep.loc(y, loc.list = locNames(y)[t3],verbose = 0)
y <- y[, order(y$loc.names)]
y <- y[order(indNames(y)), ]
s1 <- as.matrix(x)
s2 <- as.matrix(y)
s1[s1 == 2] <- 0
s2[s2 == 2] <- 0
# percentage of incorrect called genotypes between DArT and new dataset
genotypes <- nInd(y) * nLoc(y)
correct_genotypes <- sum(colSums(s1 == s2))
incorrect_percentage <- (correct_genotypes / genotypes) * 100
incorrect_percentage <- round(incorrect_percentage,2)
cat(incorrect_percentage,"percentage of", genotypes,"genotypes were the same in dataset 1 and dataset 2\n\n")
}
library(dartR)
t1 <- gl.keep.ind(
platypus.gl,ind.list = indNames(
platypus.gl)[1:10])
t2 <- gl.keep.ind(
platypus.gl,ind.list = indNames(
platypus.gl)[1:10])
genotypes_2_datasets(t1,t2)