Skip to content

Inconsistency in Results Using sum(. != 3) within Pipeline Operations (%>%) dplyr version 1.1.4 #7037

Closed
@ZHBHSMILE

Description

@ZHBHSMILE

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions