我正在创建一个最终的数据框架,其中有一个不同的珊瑚物种的列表。我已经按照我想要的方式设置了数据框。我所要做的就是将每个珊瑚物种的样本量添加到行标签中(即最终标签将看起来像这个例子。Acropora sp. (plating) n=10)。我有一个所有珊瑚物种的列表,其中包括它们的样本量,但我不确定如何将这些数据纳入行标签。
count_focal_taxa = tapply(FR3_final$Type,FR3_final$Type,length)
count_focal_taxa
``
Acropora_sp_plating Corallimorph Favia_stelligera
10 12 84
My dataframe is currently:
`
``{r}
result <- data.frame(ifelse(FR3_final_means > quantile_high, '+', ifelse(FR3_final_means < quantile_low, '-', 0)))
result$Type<-(FR3_final_means$Type)
result
```
Type A B C D E F G
Acropora_sp_plating 0 0 0 0 + 0 0
Corallimorph + 0 0 0 0 0 0
Favia_stelligera 0 0 0 0 0 - +
And I want:
Type A B C D E F G
Acropora_sp_plating n=10 0 0 0 0 + 0 0
Corallimorph n=12 + 0 0 0 0 0 0
Favia_stelligera n=84 0 0 0 0 0 - +
我们可以使用 paste
result$Type = paste(result$Type, 'n=', count_focal_taxa)
或与 sprintf
result$Type <- sprintf('%s n=%d', result$Type, count_focal_taxa)
而不是 tapply
,我们可以得到频率与 table
count_focal_taxa <- table(FR3_final$Type)