Calculates a weighted average log2 ratio for a segment given the per-observation log2 ratios and weights.

weighted_segment_log2(segment_data)

Arguments

segment_data

A data.frame with columns log2_ratio and weight.

Value

A numeric value representing the weighted average log2 ratio. Returns NA if the total weight is zero.

Details

The function computes the sum of the weights, and if non-zero, returns the weighted average of the log2 ratios. If the total weight is zero, NA is returned.

Examples

seg_data <- data.frame(log2_ratio = c(0.5, 1.2, -0.7),
                       weight = c(1, 2, 1))
ws <- weighted_segment_log2(seg_data)
print(ws)
#> [1] 0.55