How can I neatly and easy generate an out_table.
I classified groups with cutree()
of a hclust()
object. My samples are diet protocols. In my otu_table
, the diets shouöd be the samples and the taxa should be the groups.
example
#base data for the groups
base <- data.frame(row.names = c("apple","bread","banana","orange juice"),calories=c(45,87,97,30),Mg=c(45,23,89,64))
calories Mg
apple 45 45
bread 87 23
banana 97 89
orange juice 30 64
base_dist <- dist(base)
h_base <- hclust(base_dist,method="average")
cut_base <- cutree(h_base,h=0.5)
otu_diets <- mutate(base,cluster = cut_base)##adding cluster info to df
#samples
diet1 <- data.frame(row.names = c(" red apple","banana","bread","strawberry"),calories=c(45,56,72,32),Pt=c(0,23,56,45))
diet2 <- data.frame(row.names = c("banana","bread","orange juice","apple"),calories=c(45,56,75,22),Pt=c(89,23,56,45))
As you can see, in the diet protocols some food is called differently than in the base
data.frame. Also there is food in the diet protocols that does not occur in base
. I want the otu_table
to look like this
otu <- data.frame(row.names = c("diet1","diet2"),group1=c(1,1),group2=c(1,1),group3=c(1,1),group4=c(0,1))
otu <- otu_table(otu)
group1 group2 group3 group4
diet1 1 1 1 0
diet2 1 1 1 1
So the otu_table
classifies how many foods of the respective diet are in the groups. In real life I have a lot of diet protocols and many groups so I can´t do it manually like in the above example.