Using binary or discrete data with phangorn

If data are not sequence alignment an phyDat object then there are generic functions as.phyDat() in phangorn to transform a matrices and data.frames into phyDat objects. For example you can read in your data with read.table() or read.csv(), but you might need to transpose your data. For matrices as.phyDat() assumes that the entries each row belongs to one individual (taxa), but for data.frame each column. For binary data you can transform these with a command like (depending how you coded them):

as.phyDat(data, type="USER", levels = c(0, 1))
as.phyDat(data, type="USER", levels = c(TRUE, FALSE))

Often you also have missing data (e.g. -) which you want to code as ambiguous character. In this case your code may look like:

as.phyDat(data, type="USER", levels = c("0", "1"), , ambiguity="-")

More information is avaiable in one of the vignettes (type vignette("phangorn-specials", package = "phangorn") in R).