Single or double?: AND operator and OR operator in R

Yen-Chung Chen
Sep 21, 2018 · 2 min read
Photo by Jørgen Håland on Unsplash
# I don't want rows of zero here!
non_zero <- rna_seq[wt != 0 && mutant != 0 && resq !=0, ]
c(TRUE, FALSE, FALSE) & c(TRUE, TRUE, TRUE)
# If you run it in console
# [1] TRUE FALSE FALSE
FALSE & what_ever_variable# This expression is always evaluated false
# But & will still evaluate what_ever_variable before returning
# If you run it in console
# Error: object 'what_ever_variable' not found
c(TRUE, FALSE, FALSE) && c(TRUE, TRUE, TRUE)
# If you run it in console
# [1] TRUE
FALSE && what_ever_variable# With short-circuiting, && returns FALSE right after it
# gets passed FALSE and does not care what what_ever_variable is
# If you run it in console
# [1] FALSE

biosyntax

Notes, thoughts, and random experiments in life science.

Yen-Chung Chen

Written by

A learning developmental biologist

biosyntax

biosyntax

Notes, thoughts, and random experiments in life science.