Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
kingaa committed Sep 3, 2023
1 parent b6bd9ae commit 7118218
Show file tree
Hide file tree
Showing 3 changed files with 352 additions and 350 deletions.
15 changes: 8 additions & 7 deletions tutorial.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ x <- 1.9999999999999; x; x-2
x <- 1.99999999999999999; x; x-2

a <- 1; b <- 3;
c <- a < b
d <- (a > b)
c; d
c <- a < b; c
d <- (a > b); d

x <- 1:5; b <- (x<=3); b
x <- 1:5
b <- (x<=3); b

a=1:3
b=2:4
Expand All @@ -137,12 +137,12 @@ a==b
a <- c(1,2,3,4)
b <- c(1,1,5,5)
(a<b) | (a>3)
(a<b) || (a>3)
## a<b) || (a>3)

course.url <- "https://kingaa.github.io/R_Tutorial/"
X <- read.csv(paste0(course.url,"data/ChlorellaGrowth.csv"),comment.char='#')
Light <- X[,1]
rmax <- X[,2];
rmax <- X[,2]
lowLight <- Light[Light<50]
lowLightrmax <- rmax[Light<50]
lowLight
Expand Down Expand Up @@ -190,7 +190,8 @@ y <- 1:5; y
z <- array(1:5,dim=5); z
y==z
identical(y,z)
dim(y); dim(z)
dim(y)
dim(z)

## x <- seq(1,27)
## dim(x) <- c(3,9)
Expand Down
22 changes: 12 additions & 10 deletions tutorial.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -795,9 +795,8 @@ For example, try:

```{r }
a <- 1; b <- 3;
c <- a < b
d <- (a > b)
c; d
c <- a < b; c
d <- (a > b); d
```

The parentheses around `a > b` above are optional but do make the code easier to read.
Expand Down Expand Up @@ -825,7 +824,8 @@ Table: Some comparison operators in **R**. Use `?Comparison` to learn more.
When we compare two vectors or matrices, comparisons are done element-by-element (and the recycling rule applies).
For example,
```{r }
x <- 1:5; b <- (x<=3); b
x <- 1:5
b <- (x<=3); b
```
So if `x` and `y` are vectors, then `(x==y)` will return a vector of values giving the element-by-element comparisons.
If you want to know whether `x` and `y` are identical vectors, use `identical(x,y)` or `all.equal(x,y)`.
Expand Down Expand Up @@ -862,14 +862,15 @@ Table: Logical operators.

-----------------------------------

For example, try
```{r warning=TRUE,error=TRUE}
For example, execute the following and make sure you understand what happens.
```{r warning=TRUE}
a <- c(1,2,3,4)
b <- c(1,1,5,5)
(a<b) | (a>3)
(a<b) || (a>3)
```
and make sure you understand what happened.
```{r eval=FALSE}
a<b) || (a>3)
```

The two forms of logical OR (`|`and `||`) are *inclusive*, meaning that `x|y` is true if either `x` or `y` or both are true.
Use `xor` when exclusive OR is needed.
Expand All @@ -887,7 +888,7 @@ As a simple example, we might want to focus on just the low-light values of $r_{
course.url <- "https://kingaa.github.io/R_Tutorial/"
X <- read.csv(paste0(course.url,"data/ChlorellaGrowth.csv"),comment.char='#')
Light <- X[,1]
rmax <- X[,2];
rmax <- X[,2]
```
```{r }
lowLight <- Light[Light<50]
Expand Down Expand Up @@ -1110,7 +1111,8 @@ y <- 1:5; y
z <- array(1:5,dim=5); z
y==z
identical(y,z)
dim(y); dim(z)
dim(y)
dim(z)
```

-----------------------------------
Expand Down
Loading

0 comments on commit 7118218

Please sign in to comment.