r 来自https://stackoverflow.com/questions/25314336/extract-the-maximum-value-within-each-group-in-a-da

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r 来自https://stackoverflow.com/questions/25314336/extract-the-maximum-value-within-each-group-in-a-da相关的知识,希望对你有一定的参考价值。

df <- read.table(header = TRUE, text = 'Gene   Value
A      12
A      10
B      3
B      5
B      6
C      1
D      3
D      4')

# aggregate
aggregate(df$Value, by = list(df$Gene), max)
aggregate(Value ~ Gene, data = df, max)

# tapply
tapply(df$Value, df$Gene, max)

# split + lapply
lapply(split(df, df$Gene), function(y) max(y$Value))

# plyr
require(plyr)
ddply(df, .(Gene), summarise, Value = max(Value))

# dplyr
require(dplyr)
df %>% group_by(Gene) %>% summarise(Value = max(Value))

# data.table
require(data.table)
dt <- data.table(df)
dt[ , max(Value), by = Gene]

# doBy
require(doBy)
summaryBy(Value~Gene, data = df, FUN = max)

# sqldf
require(sqldf)
sqldf("select Gene, max(Value) as Value from df group by Gene", drv = 'SQLite')

# ave
df[as.logical(ave(df$Value, df$Gene, FUN = function(x) x == max(x))),]

以上是关于r 来自https://stackoverflow.com/questions/25314336/extract-the-maximum-value-within-each-group-in-a-da的主要内容,如果未能解决你的问题,请参考以下文章

ruby 来自https://stackoverflow.com/questions/2505067/class-self-idiom-in-ruby

powershell 来自https://stackoverflow.com/questions/1663748/powershell-analog-to-quote-words

text 来自https://stackoverflow.com/questions/35645839/swift-upload-video-to-http-server

text 来自https://stackoverflow.com/questions/10261265/showing-a-gif-animation-in-qlabel

csharp Fisher-Yates来自https://stackoverflow.com/questions/273313/randomize-a-listt

markdown git rm。 Elimina todos los ficheros borrados。来自:https://stackoverflow.com/a/5147119/3377046