Add second year

This commit is contained in:
2023-12-07 01:19:12 +00:00
parent 3291e5c79e
commit 3d12031ab8
1168 changed files with 431409 additions and 0 deletions

View File

@ -0,0 +1,248 @@
title:: Using R as a Calculator
- #[[ST2001 Labs]]
- **Previous Topic:** null
- **Next Topic:** [[Describing Data in R]]
- No relevant slides
-
- ## Basic Algebra in R
- ### Addition #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:13:16.517Z
card-last-reviewed:: 2022-09-18T15:13:16.518Z
card-last-score:: 5
- ```R
# to add numbers in R, simply use "+"
2+2
```
- Output:
- ```R
[1] 4
```
- ### Subtraction #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:16:58.961Z
card-last-reviewed:: 2022-09-18T15:16:58.961Z
card-last-score:: 5
- ```R
# to subtract numbers in R, simply use "-"
4-2
```
- Output:
- ```R
[1] 2
```
- ### Multiplication #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:19:10.421Z
card-last-reviewed:: 2022-09-18T15:19:10.421Z
card-last-score:: 5
- ```R
# to multiply numbers in R, simply use "*"
5*2
```
- Output:
- ```R
[1] 10
```
- ### Division #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-23T18:26:41.512Z
card-last-reviewed:: 2022-09-19T18:26:41.513Z
card-last-score:: 5
- ```R
# to divide numbers in R, simply use "/"
10/5
```
- Output:
- ```R
[1] 2
```
- ### Exponents #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-23T17:42:14.404Z
card-last-reviewed:: 2022-09-19T17:42:14.404Z
card-last-score:: 5
- ```R
# use "^" to raise a number to a power
3^2
3^{-1} # use curly braces
```
- Output:
- ```R
[1] 9
[1] 0.3333333
```
- ### Square Roots #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:21:31.602Z
card-last-reviewed:: 2022-09-18T15:21:31.603Z
card-last-score:: 5
- ```R
# use the function "sqrt()" to get the square root of a number in R
sqrt(16)
```
- Output:
- ```R
[1] 4
```
-
- ### Modulus #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:04:22.123Z
card-last-reviewed:: 2022-09-18T15:04:22.123Z
card-last-score:: 5
- ```R
# use "%%" to get the modulus
19%%6
```
- Output:
- ```R
[1] 1
```
- ## Rounding in R
- ### Absolute Value #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:13:22.206Z
card-last-reviewed:: 2022-09-18T15:13:22.208Z
card-last-score:: 5
- ```R
# use "abs()" to get absolute value in R
abs(-1)
```
- Output:
- ```R
[1] 1
```
- ### Rounding #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.46
card-next-schedule:: 2022-09-22T15:16:30.465Z
card-last-reviewed:: 2022-09-18T15:16:30.465Z
card-last-score:: 5
- The function `round()` in R goes not necessarily do what you would expect when rounding numbers ending in **.5** - ^^it rounds to the nearest **even** number.^^
- If you always round up numbers ending in .5, then you are causing an upwards bias.
- The rounding to even numbers will tend to average out at a zero bias, as 50% go up and 50% go down.
- ```R
# use "round()" to round
round(1.5)
round(0.5)
round(0.7)
```
- Output:
- ```R
[1] 2
[1] 0
[1] 1
```
- ## $\pi$ in R #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:09:00.108Z
card-last-reviewed:: 2022-09-18T15:09:00.108Z
card-last-score:: 5
- ```R
# to get pi in R, simply use the in-built constant "pi"
pi
```
- Output:
- ```R
[1] 3.141593
```
- ## Trigonometric Functions in R
- ### Sine in R #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:15:38.917Z
card-last-reviewed:: 2022-09-18T15:15:38.918Z
card-last-score:: 5
- ```R
# to get the sine of a number in R, use the function "sin()"
sin(0.5 * pi)
sin(pi)
```
- Output:
- ```R
[1] 1
[1] 1.224647e-16
```
- ^^**Note:**^^ $1.224606e-16 \approx 0$. Due to the way computers store numbers, decimals are often slightly off, so $sine(\pi) \ne 0$ even though it should, of course, be equal to zero. Be careful of this!
- ### Cosine in R #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:18:39.667Z
card-last-reviewed:: 2022-09-18T15:18:39.668Z
card-last-score:: 5
- ```R
# use "cos()" to get cosine
cos(0)
```
- Output:
- ```R
[1] 1
```
- ### Tangent in R #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-23T17:41:27.375Z
card-last-reviewed:: 2022-09-19T17:41:27.376Z
card-last-score:: 5
- ```R
# use "tan()" to get tangent
tan(0)
```
- Output:
- ```R
[1] 0
```
- ## Logarithms in R
- ### Natural Log #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-23T18:23:00.441Z
card-last-reviewed:: 2022-09-19T18:23:00.441Z
card-last-score:: 5
- ```R
log(1)
```
- Output:
- ```R`
[1] 0
```
- ### Logs to a Given Base #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.46
card-next-schedule:: 2022-09-22T15:04:49.274Z
card-last-reviewed:: 2022-09-18T15:04:49.274Z
card-last-score:: 3
- ```R
# log<base>()
log10(100)
```
- Output:
- ```R
[1] 2
```

View File

@ -0,0 +1,248 @@
title:: Using R as a Calculator
- #[[ST2001 Labs]]
- **Previous Topic:** null
- **Next Topic:** [[Describing Data in R]]
- No relevant slides
-
- ## Basic Algebra in R
- ### Addition #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:13:16.517Z
card-last-reviewed:: 2022-09-18T15:13:16.518Z
card-last-score:: 5
- ```R
# to add numbers in R, simply use "+"
2+2
```
- Output:
- ```R
[1] 4
```
- ### Subtraction #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:16:58.961Z
card-last-reviewed:: 2022-09-18T15:16:58.961Z
card-last-score:: 5
- ```R
# to subtract numbers in R, simply use "-"
4-2
```
- Output:
- ```R
[1] 2
```
- ### Multiplication #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:19:10.421Z
card-last-reviewed:: 2022-09-18T15:19:10.421Z
card-last-score:: 5
- ```R
# to multiply numbers in R, simply use "*"
5*2
```
- Output:
- ```R
[1] 10
```
- ### Division #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-23T18:26:41.512Z
card-last-reviewed:: 2022-09-19T18:26:41.513Z
card-last-score:: 5
- ```R
# to divide numbers in R, simply use "/"
10/5
```
- Output:
- ```R
[1] 2
```
- ### Exponents #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-23T17:42:14.404Z
card-last-reviewed:: 2022-09-19T17:42:14.404Z
card-last-score:: 5
- ```R
# use "^" to raise a number to a power
3^2
3^{-1} # use curly braces
```
- Output:
- ```R
[1] 9
[1] 0.3333333
```
- ### Square Roots #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:21:31.602Z
card-last-reviewed:: 2022-09-18T15:21:31.603Z
card-last-score:: 5
- ```R
# use the function "sqrt()" to get the square root of a number in R
sqrt(16)
```
- Output:
- ```R
[1] 4
```
-
- ### Modulus #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:04:22.123Z
card-last-reviewed:: 2022-09-18T15:04:22.123Z
card-last-score:: 5
- ```R
# use "%%" to get the modulus
19%%6
```
- Output:
- ```R
[1] 1
```
- ## Rounding in R
- ### Absolute Value #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:13:22.206Z
card-last-reviewed:: 2022-09-18T15:13:22.208Z
card-last-score:: 5
- ```R
# use "abs()" to get absolute value in R
abs(-1)
```
- Output:
- ```R
[1] 1
```
- ### Rounding #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.46
card-next-schedule:: 2022-09-22T15:16:30.465Z
card-last-reviewed:: 2022-09-18T15:16:30.465Z
card-last-score:: 5
- The function `round()` in R goes not necessarily do what you would expect when rounding numbers ending in **.5** - ^^it rounds to the nearest **even** number.^^
- If you always round up numbers ending in .5, then you are causing an upwards bias.
- The rounding to even numbers will tend to average out at a zero bias, as 50% go up and 50% go down.
- ```R
# use "round()" to round
round(1.5)
round(0.5)
round(0.7)
```
- Output:
- ```R
[1] 2
[1] 0
[1] 1
```
- ## $\pi$ in R #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:09:00.108Z
card-last-reviewed:: 2022-09-18T15:09:00.108Z
card-last-score:: 5
- ```R
# to get pi in R, simply use the in-built constant "pi"
pi
```
- Output:
- ```R
[1] 3.141593
```
- ## Trigonometric Functions in R
- ### Sine in R #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:15:38.917Z
card-last-reviewed:: 2022-09-18T15:15:38.918Z
card-last-score:: 5
- ```R
# to get the sine of a number in R, use the function "sin()"
sin(0.5 * pi)
sin(pi)
```
- Output:
- ```R
[1] 1
[1] 1.224647e-16
```
- ^^**Note:**^^ $1.224606e-16 \approx 0$. Due to the way computers store numbers, decimals are often slightly off, so $sine(\pi) \ne 0$ even though it should, of course, be equal to zero. Be careful of this!
- ### Cosine in R #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-22T15:18:39.667Z
card-last-reviewed:: 2022-09-18T15:18:39.668Z
card-last-score:: 5
- ```R
# use "cos()" to get cosine
cos(0)
```
- Output:
- ```R
[1] 1
```
- ### Tangent in R #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-23T17:41:27.375Z
card-last-reviewed:: 2022-09-19T17:41:27.376Z
card-last-score:: 5
- ```R
# use "tan()" to get tangent
tan(0)
```
- Output:
- ```R
[1] 0
```
- ## Logarithms in R
- ### Natural Log #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.7
card-next-schedule:: 2022-09-23T18:23:00.441Z
card-last-reviewed:: 2022-09-19T18:23:00.441Z
card-last-score:: 5
- ```R
log(1)
```
- Output:
- ```R`
[1] 0
```
- ### Logs to a Given Base #card
card-last-interval:: 4
card-repeats:: 2
card-ease-factor:: 2.46
card-next-schedule:: 2022-09-22T15:04:49.274Z
card-last-reviewed:: 2022-09-18T15:04:49.274Z
card-last-score:: 3
- ```R
# log<base>()
log10(100)
```
- Output:
- ```R
[1] 2
```

View File

@ -0,0 +1,248 @@
title:: Using R as a Calculator
- #[[ST2001 Labs]]
- **Previous Topic:** null
- **Next Topic:** [[Describing Data in R]]
- No relevant slides
-
- ## Basic Algebra in R
- ### Addition #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T17:29:23.664Z
card-last-reviewed:: 2022-10-01T13:29:23.665Z
card-last-score:: 5
- ```R
# to add numbers in R, simply use "+"
2+2
```
- Output:
- ```R
[1] 4
```
- ### Subtraction #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T21:29:47.794Z
card-last-reviewed:: 2022-10-01T17:29:47.794Z
card-last-score:: 5
- ```R
# to subtract numbers in R, simply use "-"
4-2
```
- Output:
- ```R
[1] 2
```
- ### Multiplication #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T21:35:39.178Z
card-last-reviewed:: 2022-10-01T17:35:39.178Z
card-last-score:: 5
- ```R
# to multiply numbers in R, simply use "*"
5*2
```
- Output:
- ```R
[1] 10
```
- ### Division #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-14T18:28:49.302Z
card-last-reviewed:: 2022-10-03T14:28:49.302Z
card-last-score:: 5
- ```R
# to divide numbers in R, simply use "/"
10/5
```
- Output:
- ```R
[1] 2
```
- ### Exponents #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-14T15:42:12.050Z
card-last-reviewed:: 2022-10-03T11:42:12.050Z
card-last-score:: 5
- ```R
# use "^" to raise a number to a power
3^2
3^{-1} # use curly braces
```
- Output:
- ```R
[1] 9
[1] 0.3333333
```
- ### Square Roots #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-11T12:31:00.356Z
card-last-reviewed:: 2022-09-30T08:31:00.357Z
card-last-score:: 5
- ```R
# use the function "sqrt()" to get the square root of a number in R
sqrt(16)
```
- Output:
- ```R
[1] 4
```
-
- ### Modulus #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-11T16:16:16.109Z
card-last-reviewed:: 2022-09-30T12:16:16.109Z
card-last-score:: 5
- ```R
# use "%%" to get the modulus
19%%6
```
- Output:
- ```R
[1] 1
```
- ## Rounding in R
- ### Absolute Value #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T17:29:25.342Z
card-last-reviewed:: 2022-10-01T13:29:25.343Z
card-last-score:: 5
- ```R
# use "abs()" to get absolute value in R
abs(-1)
```
- Output:
- ```R
[1] 1
```
- ### Rounding #card
card-last-interval:: 10.24
card-repeats:: 3
card-ease-factor:: 2.56
card-next-schedule:: 2022-10-11T22:28:49.505Z
card-last-reviewed:: 2022-10-01T17:28:49.505Z
card-last-score:: 5
- The function `round()` in R goes not necessarily do what you would expect when rounding numbers ending in **.5** - ^^it rounds to the nearest **even** number.^^
- If you always round up numbers ending in .5, then you are causing an upwards bias.
- The rounding to even numbers will tend to average out at a zero bias, as 50% go up and 50% go down.
- ```R
# use "round()" to round
round(1.5)
round(0.5)
round(0.7)
```
- Output:
- ```R
[1] 2
[1] 0
[1] 1
```
- ## $\pi$ in R #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-11T16:10:40.446Z
card-last-reviewed:: 2022-09-30T12:10:40.446Z
card-last-score:: 5
- ```R
# to get pi in R, simply use the in-built constant "pi"
pi
```
- Output:
- ```R
[1] 3.141593
```
- ## Trigonometric Functions in R
- ### Sine in R #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-11T12:29:09.246Z
card-last-reviewed:: 2022-09-30T08:29:09.246Z
card-last-score:: 5
- ```R
# to get the sine of a number in R, use the function "sin()"
sin(0.5 * pi)
sin(pi)
```
- Output:
- ```R
[1] 1
[1] 1.224647e-16
```
- ^^**Note:**^^ $1.224606e-16 \approx 0$. Due to the way computers store numbers, decimals are often slightly off, so $sine(\pi) \ne 0$ even though it should, of course, be equal to zero. Be careful of this!
- ### Cosine in R #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T21:35:15.641Z
card-last-reviewed:: 2022-10-01T17:35:15.641Z
card-last-score:: 5
- ```R
# use "cos()" to get cosine
cos(0)
```
- Output:
- ```R
[1] 1
```
- ### Tangent in R #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-14T15:41:56.642Z
card-last-reviewed:: 2022-10-03T11:41:56.643Z
card-last-score:: 5
- ```R
# use "tan()" to get tangent
tan(0)
```
- Output:
- ```R
[1] 0
```
- ## Logarithms in R
- ### Natural Log #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-14T15:45:32.515Z
card-last-reviewed:: 2022-10-03T11:45:32.515Z
card-last-score:: 5
- ```R
log(1)
```
- Output:
- ```R`
[1] 0
```
- ### Logs to a Given Base #card
card-last-interval:: 10.24
card-repeats:: 3
card-ease-factor:: 2.56
card-next-schedule:: 2022-10-10T17:16:21.935Z
card-last-reviewed:: 2022-09-30T12:16:21.935Z
card-last-score:: 5
- ```R
# log<base>()
log10(100)
```
- Output:
- ```R
[1] 2
```

View File

@ -0,0 +1,248 @@
title:: Using R as a Calculator
- #[[ST2001 Labs]]
- **Previous Topic:** null
- **Next Topic:** [[Describing Data in R]]
- No relevant slides
-
- ## Basic Algebra in R
- ### Addition #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T17:29:23.664Z
card-last-reviewed:: 2022-10-01T13:29:23.665Z
card-last-score:: 5
- ```R
# to add numbers in R, simply use "+"
2+2
```
- Output:
- ```R
[1] 4
```
- ### Subtraction #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T21:29:47.794Z
card-last-reviewed:: 2022-10-01T17:29:47.794Z
card-last-score:: 5
- ```R
# to subtract numbers in R, simply use "-"
4-2
```
- Output:
- ```R
[1] 2
```
- ### Multiplication #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T21:35:39.178Z
card-last-reviewed:: 2022-10-01T17:35:39.178Z
card-last-score:: 5
- ```R
# to multiply numbers in R, simply use "*"
5*2
```
- Output:
- ```R
[1] 10
```
- ### Division #card
card-last-interval:: 33.64
card-repeats:: 4
card-ease-factor:: 2.9
card-next-schedule:: 2022-11-22T23:24:36.469Z
card-last-reviewed:: 2022-10-20T08:24:36.470Z
card-last-score:: 5
- ```R
# to divide numbers in R, simply use "/"
10/5
```
- Output:
- ```R
[1] 2
```
- ### Exponents #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-14T15:42:12.050Z
card-last-reviewed:: 2022-10-03T11:42:12.050Z
card-last-score:: 5
- ```R
# use "^" to raise a number to a power
3^2
3^{-1} # use curly braces
```
- Output:
- ```R
[1] 9
[1] 0.3333333
```
- ### Square Roots #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-11T12:31:00.356Z
card-last-reviewed:: 2022-09-30T08:31:00.357Z
card-last-score:: 5
- ```R
# use the function "sqrt()" to get the square root of a number in R
sqrt(16)
```
- Output:
- ```R
[1] 4
```
-
- ### Modulus #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-11T16:16:16.109Z
card-last-reviewed:: 2022-09-30T12:16:16.109Z
card-last-score:: 5
- ```R
# use "%%" to get the modulus
19%%6
```
- Output:
- ```R
[1] 1
```
- ## Rounding in R
- ### Absolute Value #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T17:29:25.342Z
card-last-reviewed:: 2022-10-01T13:29:25.343Z
card-last-score:: 5
- ```R
# use "abs()" to get absolute value in R
abs(-1)
```
- Output:
- ```R
[1] 1
```
- ### Rounding #card
card-last-interval:: 10.24
card-repeats:: 3
card-ease-factor:: 2.56
card-next-schedule:: 2022-10-11T22:28:49.505Z
card-last-reviewed:: 2022-10-01T17:28:49.505Z
card-last-score:: 5
- The function `round()` in R goes not necessarily do what you would expect when rounding numbers ending in **.5** - ^^it rounds to the nearest **even** number.^^
- If you always round up numbers ending in .5, then you are causing an upwards bias.
- The rounding to even numbers will tend to average out at a zero bias, as 50% go up and 50% go down.
- ```R
# use "round()" to round
round(1.5)
round(0.5)
round(0.7)
```
- Output:
- ```R
[1] 2
[1] 0
[1] 1
```
- ## $\pi$ in R #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-11T16:10:40.446Z
card-last-reviewed:: 2022-09-30T12:10:40.446Z
card-last-score:: 5
- ```R
# to get pi in R, simply use the in-built constant "pi"
pi
```
- Output:
- ```R
[1] 3.141593
```
- ## Trigonometric Functions in R
- ### Sine in R #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-11T12:29:09.246Z
card-last-reviewed:: 2022-09-30T08:29:09.246Z
card-last-score:: 5
- ```R
# to get the sine of a number in R, use the function "sin()"
sin(0.5 * pi)
sin(pi)
```
- Output:
- ```R
[1] 1
[1] 1.224647e-16
```
- ^^**Note:**^^ $1.224606e-16 \approx 0$. Due to the way computers store numbers, decimals are often slightly off, so $sine(\pi) \ne 0$ even though it should, of course, be equal to zero. Be careful of this!
- ### Cosine in R #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T21:35:15.641Z
card-last-reviewed:: 2022-10-01T17:35:15.641Z
card-last-score:: 5
- ```R
# use "cos()" to get cosine
cos(0)
```
- Output:
- ```R
[1] 1
```
- ### Tangent in R #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-14T15:41:56.642Z
card-last-reviewed:: 2022-10-03T11:41:56.643Z
card-last-score:: 5
- ```R
# use "tan()" to get tangent
tan(0)
```
- Output:
- ```R
[1] 0
```
- ## Logarithms in R
- ### Natural Log #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-14T15:45:32.515Z
card-last-reviewed:: 2022-10-03T11:45:32.515Z
card-last-score:: 5
- ```R
log(1)
```
- Output:
- ```R`
[1] 0
```
- ### Logs to a Given Base #card
card-last-interval:: -1
card-repeats:: 1
card-ease-factor:: 2.56
card-next-schedule:: 2022-10-20T23:00:00.000Z
card-last-reviewed:: 2022-10-20T08:35:14.456Z
card-last-score:: 1
- ```R
# log<base>()
log10(100)
```
- Output:
- ```R
[1] 2
```

View File

@ -0,0 +1,248 @@
title:: Using R as a Calculator
- #[[ST2001 Labs]]
- **Previous Topic:** null
- **Next Topic:** [[Describing Data in R]]
- No relevant slides
-
- ## Basic Algebra in R
- ### Addition #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T17:29:23.664Z
card-last-reviewed:: 2022-10-01T13:29:23.665Z
card-last-score:: 5
- ```R
# to add numbers in R, simply use "+"
2+2
```
- Output:
- ```R
[1] 4
```
- ### Subtraction #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T21:29:47.794Z
card-last-reviewed:: 2022-10-01T17:29:47.794Z
card-last-score:: 5
- ```R
# to subtract numbers in R, simply use "-"
4-2
```
- Output:
- ```R
[1] 2
```
- ### Multiplication #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T21:35:39.178Z
card-last-reviewed:: 2022-10-01T17:35:39.178Z
card-last-score:: 5
- ```R
# to multiply numbers in R, simply use "*"
5*2
```
- Output:
- ```R
[1] 10
```
- ### Division #card
card-last-interval:: 33.64
card-repeats:: 4
card-ease-factor:: 2.9
card-next-schedule:: 2022-11-22T23:24:36.469Z
card-last-reviewed:: 2022-10-20T08:24:36.470Z
card-last-score:: 5
- ```R
# to divide numbers in R, simply use "/"
10/5
```
- Output:
- ```R
[1] 2
```
- ### Exponents #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-14T15:42:12.050Z
card-last-reviewed:: 2022-10-03T11:42:12.050Z
card-last-score:: 5
- ```R
# use "^" to raise a number to a power
3^2
3^{-1} # use curly braces
```
- Output:
- ```R
[1] 9
[1] 0.3333333
```
- ### Square Roots #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-11T12:31:00.356Z
card-last-reviewed:: 2022-09-30T08:31:00.357Z
card-last-score:: 5
- ```R
# use the function "sqrt()" to get the square root of a number in R
sqrt(16)
```
- Output:
- ```R
[1] 4
```
-
- ### Modulus #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-11T16:16:16.109Z
card-last-reviewed:: 2022-09-30T12:16:16.109Z
card-last-score:: 5
- ```R
# use "%%" to get the modulus
19%%6
```
- Output:
- ```R
[1] 1
```
- ## Rounding in R
- ### Absolute Value #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T17:29:25.342Z
card-last-reviewed:: 2022-10-01T13:29:25.343Z
card-last-score:: 5
- ```R
# use "abs()" to get absolute value in R
abs(-1)
```
- Output:
- ```R
[1] 1
```
- ### Rounding #card
card-last-interval:: 10.24
card-repeats:: 3
card-ease-factor:: 2.56
card-next-schedule:: 2022-10-11T22:28:49.505Z
card-last-reviewed:: 2022-10-01T17:28:49.505Z
card-last-score:: 5
- The function `round()` in R goes not necessarily do what you would expect when rounding numbers ending in **.5** - ^^it rounds to the nearest **even** number.^^
- If you always round up numbers ending in .5, then you are causing an upwards bias.
- The rounding to even numbers will tend to average out at a zero bias, as 50% go up and 50% go down.
- ```R
# use "round()" to round
round(1.5)
round(0.5)
round(0.7)
```
- Output:
- ```R
[1] 2
[1] 0
[1] 1
```
- ## $\pi$ in R #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-11T16:10:40.446Z
card-last-reviewed:: 2022-09-30T12:10:40.446Z
card-last-score:: 5
- ```R
# to get pi in R, simply use the in-built constant "pi"
pi
```
- Output:
- ```R
[1] 3.141593
```
- ## Trigonometric Functions in R
- ### Sine in R #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-11T12:29:09.246Z
card-last-reviewed:: 2022-09-30T08:29:09.246Z
card-last-score:: 5
- ```R
# to get the sine of a number in R, use the function "sin()"
sin(0.5 * pi)
sin(pi)
```
- Output:
- ```R
[1] 1
[1] 1.224647e-16
```
- ^^**Note:**^^ $1.224606e-16 \approx 0$. Due to the way computers store numbers, decimals are often slightly off, so $sine(\pi) \ne 0$ even though it should, of course, be equal to zero. Be careful of this!
- ### Cosine in R #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-12T21:35:15.641Z
card-last-reviewed:: 2022-10-01T17:35:15.641Z
card-last-score:: 5
- ```R
# use "cos()" to get cosine
cos(0)
```
- Output:
- ```R
[1] 1
```
- ### Tangent in R #card
card-last-interval:: 11.2
card-repeats:: 3
card-ease-factor:: 2.8
card-next-schedule:: 2022-10-14T15:41:56.642Z
card-last-reviewed:: 2022-10-03T11:41:56.643Z
card-last-score:: 5
- ```R
# use "tan()" to get tangent
tan(0)
```
- Output:
- ```R
[1] 0
```
- ## Logarithms in R
- ### Natural Log #card
card-last-interval:: 28.3
card-repeats:: 4
card-ease-factor:: 2.66
card-next-schedule:: 2022-12-07T19:44:02.657Z
card-last-reviewed:: 2022-11-09T12:44:02.657Z
card-last-score:: 3
- ```R
log(1)
```
- Output:
- ```R`
[1] 0
```
- ### Logs to a Given Base #card
card-last-interval:: -1
card-repeats:: 1
card-ease-factor:: 2.56
card-next-schedule:: 2022-10-20T23:00:00.000Z
card-last-reviewed:: 2022-10-20T08:35:14.456Z
card-last-score:: 1
- ```R
# log<base>()
log10(100)
```
- Output:
- ```R
[1] 2
```