gethierarchy(x, formula = NULL, combine = TRUE)sethierarchy(x, value)
sethierarchy(x) <- value
namehierarchy(x, value)
namehierarchy(x) <- value
splithierarchy(x, value, sep = "_")
splithierarchy(x) <- value
addhierarchy(x, value, name = "NEW")
addhierarchy(x) <- value
TRUE
, the levels will be combined according to the
formula argument. If it is FALSE
, the levels will not be combined.character
indicating the character used to separate
hierarchical levels. This defaults to "_".splitcombine
. It is often
difficult to import files with several levels of hierarchy as most data
formats do not allow unlimited population levels. This is circumvented by
collapsing all hierarchical levels into a single population factor with a
common separator for each observation. This function will then split those
hierarchies for you, but it works best on a hierarchy that only has a single
column in it. See the rootrot example below.These functions allow the user to seamlessly assign the hierarchical levels
of their
object. Note that there are two ways
of performing all methods (except for gethierarchy()
). They
essentially do the same thing except that the assignment method (the one with
the "<-
") will modify the object in place whereas the non-assignment
method will not modify the original object. Due to convention, everything
right of the assignment is termed value
. To avoid confusion, here is a
guide to the inputs:
data.frame
that defines the hierarchy for each individual in
the rows.vector
or aformula
that will define the names.formula
argument
with the same number of levels as the hierarchy you wish to split.vector
ordata.frame
with the same length as the number of individuals in
your data.The preferred use of these functions is with a formula
object.
Specifically, a hierarchical formula argument is used to assign the levels of
the hierarchy. An example of a hierarchical formula would be:
~Country/City/Neighborhood
or
~Country + Country:City +
Country:City:Neighborhood
of course, the first method is slightly easier
to read. It is important to use hiearchical formulas when specifying
hierarchies as other types of formulas (eg.
~Country*City*Neighborhood
) might give spurious results.}
setpop
genclone
as.genclone
# let's look at the microbov data set:
data(microbov)
microgc <- as.genclone(microbov)
microgc
# We see that we have three vectors of different names here.
?microbov
# These are Country, Breed, and Species
names(other(microgc))
# Let's set the hierarchy
sethierarchy(microgc) <- data.frame(other(microgc))
microgc
# And change the names so we know what they are
namehierarchy(microgc) <- ~Country/Breed/Species
# let's see what the hierarchy looks like by Species and Breed:
head(gethierarchy(microgc, ~Breed/Species))
# Load our data set and convert it to a genclone object.
Aeut.gc <- read.genalex(system.file("files/rootrot.csv", package = "poppr"))
# we can see the hierarchy is set to Population_Subpopulation.
head(gethierarchy(Aeut.gc))
# We can use splithierarchy() to split them.
splithierarchy(Aeut.gc) <- ~Pop/Subpop
Aeut.gc
head(gethierarchy(Aeut.gc))
# We can also use gethierarchy to combine the hierarchy.
head(gethierarchy(Aeut.gc, ~Pop/Subpop))
# We can also give it a more descriptive name.
namehierarchy(Aeut.gc) <- ~Population/Subpopulation
Aeut.gc
Aeut.gc <- namehierarchy(Aeut.gc, ~Pop/Subpop)
Aeut.gc
Run the code above in your browser using DataLab