R/read.structure.R

Defines functions read.structure

Documented in read.structure

read.structure <- function(file, suffix = c("A", "B")) {
	f <- file(file)
	dat <- readLines(f)
	close(f)
	dat <- strsplit(dat, "\\s+")
	loci <- dat[[1L]]
	dat <- do.call(rbind, dat[-1L])
	indnames <- dat[, 1L]
	dat <- dat[, -1L]
	dat <- array(as.integer(dat), dim = dim(dat))
	patches <- dat[, 1L]
	dat <- dat[, -1L]
	dat[dat <= 0] <- NA_integer_
	res <- data.frame(patch = patches)
	res <- cbind(res, dat)
	rownames(res) <- indnames
	colnames(res)[-1L] <- paste(rep(loci, each = 2L), suffix, sep = ".")
	res
}

Try the ibmpm package in your browser

Any scripts or data that you put into this service are public.

ibmpm documentation built on May 2, 2019, 5:45 p.m.