From 80aec62b56daac5e12be3f5169fc3ddf91c1a46d Mon Sep 17 00:00:00 2001 From: robertchu03 <47870119+robertchu03@users.noreply.github.com> Date: Thu, 16 Jan 2020 02:23:51 +0800 Subject: [PATCH] Correct typo or explanation (#818) 11 | 12 should be enclosed in parentheses otherwise the explanation is incorrect (Issue #704) --- transform.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transform.Rmd b/transform.Rmd index 8af7dd1..acb2c8b 100644 --- a/transform.Rmd +++ b/transform.Rmd @@ -125,7 +125,7 @@ The following code finds all flights that departed in November or December: filter(flights, month == 11 | month == 12) ``` -The order of operations doesn't work like English. You can't write `filter(flights, month == 11 | 12)`, which you might literally translate into "finds all flights that departed in November or December". Instead it finds all months that equal `11 | 12`, an expression that evaluates to `TRUE`. In a numeric context (like here), `TRUE` becomes one, so this finds all flights in January, not November or December. This is quite confusing! +The order of operations doesn't work like English. You can't write `filter(flights, month == (11 | 12))`, which you might literally translate into "finds all flights that departed in November or December". Instead it finds all months that equal `11 | 12`, an expression that evaluates to `TRUE`. In a numeric context (like here), `TRUE` becomes one, so this finds all flights in January, not November or December. This is quite confusing! A useful short-hand for this problem is `x %in% y`. This will select every row where `x` is one of the values in `y`. We could use it to rewrite the code above: