简体   繁体   English

每行的最大列数

[英]Max Column for each Row

I'm an R novice, so I can't make a sample data frame for you, for which I apologize. 我是R新手,因此无法为您制作示例数据框,对此深表歉意。 However, I'm doing bacterial community analysis and I have a table that has species for each column and each sample for each row. 但是,我正在进行细菌群落分析,并且有一张表格,该表格的每一列都有样本,每一行都有样本。 Each column is an identifier for each species. 每列是每个物种的标识符。 Within the data frame is the species abundance for each sample. 数据框中包含每个样本的物种丰度。 My goal is to identify the most abundant species (column) for each sample (row). 我的目标是为每个样本(行)确定最丰富的物种(列)。 I think making a data frame that has samples (rows) with the most abundant species column identifier would be the most useful! 我认为,制作一个包含样本(行)的物种列标识符最丰富的数据帧将是最有用的! Iterations I've tried (using phyloseq package, but can be used without this package). 我尝试过的迭代(使用phyloseq程序包,但无需此程序包也可以使用)。

beagle <- names(sort(taxa_sums(top.pdy.phyl),T, function(x) which(max==x)))
beagle2 <- names(taxa_sums(top.pdy.phyl),T, function(x) colnames(which.max(top.pdy.phyl))))

Any help would be appreciated! 任何帮助,将不胜感激! Thank you! 谢谢!

How about: 怎么样:

names(top.pdy.phyl)[ apply(top.pdy.phyl, 1, which.max) ]

and

apply(top.pdy.phyl, 1 , max)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM