R语言手动计算N50
# 定义计算N50的函数
compute_N50 <- function(lengths) {
total_length <- sum(lengths)
half_total_length <- total_length * 0.5 (N50;N90则乘以0.9)
sorted_lengths <- sort(lengths, decreasing = TRUE)
cumulative_length <- cumsum(sorted_lengths)
n50_index <- which(cumulative_length >= half_total_length)[1]
n50_value <- sorted_lengths[n50_index]
return(n50_value)
}
# 示例长度列表
lengths <- c(100, 200, 150, 75, 300, 250, 125)
## 计算N50
compute_N50(lengths)