Closed
Description
I encountered an inconsistency in the results obtained from different approaches while working with R code. Specifically, when using the sum(. != 3) expression within a pipeline operation (%>%), the outcome varied from expectations, leading to discrepancies compared to direct computations.
data <- data.frame(
GO.BiologicalProcess = c("-", "-", "A", "B"),
GO.CellularComponent = c("-", "C", "-", "D"),
GO.MolecularFunction = c("-", "-", "-", "E")
)
# Calculate the number of occurrences of "-" in each row
go_num <- rowSums(data[, c("GO.BiologicalProcess", "GO.CellularComponent", "GO.MolecularFunction")] == "-")
# Calculate the sum of occurrences where the count is not equal to 3
go_bg_num <- sum(go_num != 3)
# Using pipe operator and sum(. != 3)
error_sum <- rowSums(data[, c("GO.BiologicalProcess", "GO.CellularComponent", "GO.MolecularFunction")] == "-") %>% sum(. != 3)
Metadata
Metadata
Assignees
Labels
No labels