# open an example dataset (HapMap)
genofile <- snpgdsOpen(snpgdsExampleFileName())
sample.id <- read.gdsn(index.gdsn(genofile, "sample.id"))
PCARV <- snpgdsPCA(genofile, eigen.cnt=8)
SnpLoad <- snpgdsPCASNPLoading(PCARV, genofile)
# calculate sample eigenvectors from SNP loadings
SL <- snpgdsPCASampLoading(SnpLoad, genofile, sample.id=sample.id[1:100])
diff <- PCARV$eigenvect[1:100,] - SL$eigenvect
summary(c(diff))
# ~ ZERO
# close the genotype file
snpgdsClose(genofile)
Run the code above in your browser using DataLab