【发布时间】:2018-03-09 13:53:50
【问题描述】:
我想在下表中找到每个基因的最大值和最小值。 我知道,以下函数给出了最大值(或最小值),但我无法同时获得两者。
tapply(df$Value, df$Gene, max)
欣赏!
小测试集:
df <- read.table(header = TRUE, text = 'Gene Value
A 12
A 10
A 123
A 1
B 3
B 5
B 6
C 1
D 3
D 45
D 98
D 234
D 4')
【问题讨论】:
-
试试
library(dplyr);df %>% group_by(Gene) %>% summarise(Min = min(Value), Max = max(Value)) -
range(x)返回一个二元素向量,其最小值和最大值为x -
tapply(df$Value, df$Gene, FUN = function(x) c(max = max(x), min = min(x)))? -
aggregate(Value ~ Gene, data=df, FUN=range)
标签: r