-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
217 changed files
with
19,854 additions
and
9 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
_freeze/0_unpublished/danger_disturb/execute-results/html.json
Large diffs are not rendered by default.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
_freeze/posts/code_along_with_me/danger_disturb/danger_disturb/execute-results/html.json
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+35.9 KB
..._along_with_me/danger_disturb/danger_disturb/figure-html/unnamed-chunk-13-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+70.4 KB
..._along_with_me/danger_disturb/danger_disturb/figure-html/unnamed-chunk-14-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+32.6 KB
..._along_with_me/danger_disturb/danger_disturb/figure-html/unnamed-chunk-15-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+69.6 KB
..._along_with_me/danger_disturb/danger_disturb/figure-html/unnamed-chunk-16-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.8 KB
..._along_with_me/danger_disturb/danger_disturb/figure-html/unnamed-chunk-17-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+59 KB
..._along_with_me/danger_disturb/danger_disturb/figure-html/unnamed-chunk-18-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.6 KB
...e_along_with_me/danger_disturb/danger_disturb/figure-html/unnamed-chunk-2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.6 KB
...e_along_with_me/danger_disturb/danger_disturb/figure-html/unnamed-chunk-3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.4 KB
...e_along_with_me/danger_disturb/danger_disturb/figure-html/unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+24.3 KB
...e_along_with_me/danger_disturb/danger_disturb/figure-html/unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions
20
_freeze/posts/code_along_with_me/new_post_1/danger_disturb/execute-results/html.json
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+35.9 KB
...code_along_with_me/new_post_1/danger_disturb/figure-html/unnamed-chunk-13-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+70.4 KB
...code_along_with_me/new_post_1/danger_disturb/figure-html/unnamed-chunk-14-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+32.6 KB
...code_along_with_me/new_post_1/danger_disturb/figure-html/unnamed-chunk-15-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+69.6 KB
...code_along_with_me/new_post_1/danger_disturb/figure-html/unnamed-chunk-16-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.8 KB
...code_along_with_me/new_post_1/danger_disturb/figure-html/unnamed-chunk-17-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+59 KB
...code_along_with_me/new_post_1/danger_disturb/figure-html/unnamed-chunk-18-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.6 KB
.../code_along_with_me/new_post_1/danger_disturb/figure-html/unnamed-chunk-2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.6 KB
.../code_along_with_me/new_post_1/danger_disturb/figure-html/unnamed-chunk-3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.4 KB
.../code_along_with_me/new_post_1/danger_disturb/figure-html/unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+24.3 KB
.../code_along_with_me/new_post_1/danger_disturb/figure-html/unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions
14
_freeze/posts/r_rstudio/new_post_2/post_2/execute-results/html.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"hash": "24c6f9027f439b1d4fed6b1a287db4d2", | ||
"result": { | ||
"markdown": "---\ntitle: \"The Basics of R and RStudio\"\nsubtitle: \"Part 1: Simple Arithmetic\"\nauthor: \"William Okech\"\ndate: \"2022-06-15\"\nimage: \"r_and_rstudio.png\"\ncategories: [RStudio, R, Tutorial, Blog]\ntoc: true\ndraft: false\n---\n\n\n## Introduction\n\nThis is the first in a series of blog posts looking at the basics of R and RStudio. These programs allow us to perform various basic and complex calculations.\n\nTo get started, first, we will open R or RStudio. In R, go to the console, and in RStudio, head to the console pane. Next, type in a basic arithmetic calculation such as \"1 + 1\" after the angle bracket (\\>) and hit \"Enter.\"\n\nAn example of a basic calculation:\n\n\n::: {.cell}\n\n```{.r .cell-code}\n1+1\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 2\n```\n:::\n:::\n\n\nThe output will be observed next to the square bracket containing the number 1 (\\[1\\]).\n\n{fig-align=\"center\" width=\"90%\"}\n\nAdditionally, to include comments into the code block we use the hash (#) symbol. Anything written after the code block will be commented out and not run.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# A simple arithmetic calculation (which is not run because of the hash symbol)\n1+1\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 2\n```\n:::\n:::\n\n\n## Arithmetic operators available in R/RStudio\n\nVarious arithmetic operators (listed below) can be used in R/RStudio.\n\n| Arithmetic Operator | Description |\n|:-------------------:|:----------------------------------:|\n| \\+ | Addition |\n| \\- | Subtraction |\n| \\* | Multiplication |\n| / | Division |\n| \\*\\* or \\^ | Exponentiation |\n| %% | Modulus (remainder after division) |\n| %/% | Integer division |\n\n## Examples\n\n### Addition\n\n\n::: {.cell}\n\n```{.r .cell-code}\n10+30\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 40\n```\n:::\n:::\n\n\n### Subtraction\n\n\n::: {.cell}\n\n```{.r .cell-code}\n30-24\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 6\n```\n:::\n:::\n\n\n### Multiplication\n\n\n::: {.cell}\n\n```{.r .cell-code}\n20*4\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 80\n```\n:::\n:::\n\n\n### Division\n\n\n::: {.cell}\n\n```{.r .cell-code}\n93/4\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 23.25\n```\n:::\n:::\n\n\n### Exponentiation\n\n\n::: {.cell}\n\n```{.r .cell-code}\n3^6\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 729\n```\n:::\n:::\n\n\n### Modulus (remainder with division)\n\n\n::: {.cell}\n\n```{.r .cell-code}\n94%%5\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 4\n```\n:::\n:::\n\n\n### Integer Division\n\n\n::: {.cell}\n\n```{.r .cell-code}\n54%/%7\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 7\n```\n:::\n:::\n\n\n### Slightly more complex arithmetic operations\n\n\n::: {.cell}\n\n```{.r .cell-code}\n5-1+(4*3)/16*3\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 6.25\n```\n:::\n:::\n", | ||
"supporting": [], | ||
"filters": [ | ||
"rmarkdown/pagebreak.lua" | ||
], | ||
"includes": {}, | ||
"engineDependencies": {}, | ||
"preserve": {}, | ||
"postProcess": true | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
_freeze/posts/r_rstudio/new_post_3/post_3/execute-results/html.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"hash": "66087bd080a48fbfddc668e0ea367fa4", | ||
"result": { | ||
"markdown": "---\ntitle: \"The Basics of R and RStudio\"\nsubtitle: \"Part 2: Variables\"\nauthor: \"William Okech\"\ndate: \"2022-06-22\"\nimage: \"r_and_rstudio.png\"\ncategories: [RStudio, R, Tutorial, Blog]\ntoc: true\ndraft: false\n---\n\n\n## Introduction\n\nVariables are instrumental in programming because they are used as \"containers\" to store data values.\n\nTo assign a value to a variable, we can use `<−` or `=`. However, most R users prefer to use `<−`.\n\n## Variable assignment\n\n### 1. Using `<-`\n\n\n::: {.cell}\n\n```{.r .cell-code}\nvariable_1 <- 5\nvariable_1\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 5\n```\n:::\n:::\n\n\n### 2. Using `=`\n\n\n::: {.cell}\n\n```{.r .cell-code}\nvariable_2 = 10\nvariable_2\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 10\n```\n:::\n:::\n\n\n### 3. Reverse the value and variable with `->`\n\n\n::: {.cell}\n\n```{.r .cell-code}\n15 -> variable_3\nvariable_3\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 15\n```\n:::\n:::\n\n\n### 4. Assign two variables to one value\n\n\n::: {.cell}\n\n```{.r .cell-code}\nvariable_4 <- variable_5 <- 30\nvariable_4\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 30\n```\n:::\n\n```{.r .cell-code}\nvariable_5\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 30\n```\n:::\n:::\n\n\n## Variable output\n\nThe output of the variable can then be obtained by:\n\n1. Typing the variable name and then pressing \"Enter,\"\n2. Typing \"print\" with the variable name in brackets, `print(variable)`, and\n3. Typing \"View\" with the variable name in brackets, `View(variable)`.\n\nBoth `print()` and `View()` are some of the many built-in functions[^1] available in R.\n\n[^1]: Functions are a collection of statements (organized and reusable code) that perform a specific task, and R has many built-in functions.\n\nIn RStudio, the list of variables that have been loaded can be viewed in the environment pane.\n\n{fig-align=\"center\" width=\"90%\"}\n\nFigure 1: A screenshot of the environment pane with the stored variables.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nprint(variable_1)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 5\n```\n:::\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nView(variable_2)\n```\n:::\n\n\nOutput of `View()` will be seen in the script pane\n\n## The `assign()` and `rm()` functions\n\nIn addition to using the assignment operators (`<-` and `=`), we can use the `assign()` function to assign a value to a variable.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nassign(\"variable_6\", 555)\nvariable_6\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 555\n```\n:::\n:::\n\n\nTo remove the assignment of the value to the variable, either delete the variable in the \"environment pane\" or use the `rm()` function.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nvariable_7 <- 159\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nrm(variable_7)\n```\n:::\n\n\nAfter running `rm()` look at the environment pane to confirm whether `variable_7` has been removed.\n\n## Naming variables\n\nAt this point, you may be wondering what conventions are used for naming variables. First, variables need to have meaningful names such as current_temp, time_24_hr, or weight_lbs. However, we need to be mindful of the [variable](https://web.stanford.edu/class/cs109l/unrestricted/resources/google-style.html) [style guide](http://adv-r.had.co.nz/Style.html) which provides us with the appropriate rules for naming variables.\n\nSome rules to keep in mind are:\n\n1. R is case-sensitive (`variable` is not the same as `Variable`),\n2. Names similar to typical outputs or functions (`TRUE`, `FALSE`, `if`, or `else`) cannot be used,\n3. Appropriate variable names can contain letters, numbers, dots, and underscores. However, you cannot start with an underscore, number, or dot followed by a number.\n\n## Valid and invalid names\n\n### Valid names:\n\n- time_24_hr\n- .time24_hr\n\n### Invalid names:\n\n- \\_24_hr.time\n- 24_hr_time\n- .24_hr_time\n", | ||
"supporting": [], | ||
"filters": [ | ||
"rmarkdown/pagebreak.lua" | ||
], | ||
"includes": {}, | ||
"engineDependencies": {}, | ||
"preserve": {}, | ||
"postProcess": true | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
_freeze/posts/r_rstudio/new_post_4/post_4/execute-results/html.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"hash": "422f19d53489a0b7f72a6fc11e2e947b", | ||
"result": { | ||
"markdown": "---\ntitle: \"The Basics of R and RStudio\"\nsubtitle: \"Part 3: Data Types\"\nauthor: \"William Okech\"\ndate: \"2022-06-23\"\nimage: \"r_and_rstudio.png\"\ncategories: [RStudio, R, Tutorial, Blog]\ntoc: true\ndraft: false\n---\n\n\n## Introduction\n\nR and RStudio utilize multiple data types to store different kinds of data.\n\nThe most common data types in R are listed below.\n\n| **Data Type** | **Description** |\n|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Numeric | The most common data type. The values can be numbers or decimals (all real numbers). |\n| Integer | Special case of numeric data without decimals. |\n| Logical | Boolean data type with only 2 values (`TRUE` or `FALSE`). |\n| Complex | Specifies imaginary values in R. |\n| Character | Assigns a character or string to a variable. The character variables are enclosed in single quotes ('character') while the string variables are enclosed in double quotes (\"string\"). |\n| Factor | Special type of character variable that represents a categorical such as gender. |\n| Raw | Specifies values as raw bytes. It uses built-in functions to convert between raw and character (charToRaw() or rawToChar()). |\n| Dates | Specifies the date variable. Date stores a date and POSIXct stores a date and time. The output is indicated as the number of days (Date) or number of seconds (POSIXct) since 01/01/1970. |\n\n## Data types\n\n### 1. Numeric\n\n\n::: {.cell}\n\n```{.r .cell-code}\n89.98\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 89.98\n```\n:::\n\n```{.r .cell-code}\n55\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 55\n```\n:::\n:::\n\n\n### 2. Integer\n\n\n::: {.cell}\n\n```{.r .cell-code}\n5L\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 5\n```\n:::\n\n```{.r .cell-code}\n5768L\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 5768\n```\n:::\n:::\n\n\n### 3. Logical\n\n\n::: {.cell}\n\n```{.r .cell-code}\nTRUE\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] TRUE\n```\n:::\n\n```{.r .cell-code}\nFALSE\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] FALSE\n```\n:::\n:::\n\n\n### 4. Complex\n\n\n::: {.cell}\n\n```{.r .cell-code}\n10 + 30i\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 10+30i\n```\n:::\n\n```{.r .cell-code}\n287 + 34i\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 287+34i\n```\n:::\n:::\n\n\n### 5. Character or String\n\n\n::: {.cell}\n\n```{.r .cell-code}\n'abc'\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"abc\"\n```\n:::\n\n```{.r .cell-code}\n\"def\"\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"def\"\n```\n:::\n\n```{.r .cell-code}\n\"I like learning R\"\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"I like learning R\"\n```\n:::\n:::\n\n\n### 6. Dates\n\n\n::: {.cell}\n\n```{.r .cell-code}\n\"2022-06-23 14:39:21 EAT\"\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"2022-06-23 14:39:21 EAT\"\n```\n:::\n\n```{.r .cell-code}\n\"2022-06-23\"\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"2022-06-23\"\n```\n:::\n:::\n\n\n## Examining various data types\n\nSeveral functions exist to examine the features of the various data types. These include:\n\n1. `typeof()` -- what is the data type of the object (low-level)?\n2. `class()` -- what is the data type of the object (high-level)?\n3. `length()` -- how long is the object?\n4. `attributes()` -- any metadata available?\n\nLet's look at how these functions work with a few examples\n\n\n::: {.cell}\n\n```{.r .cell-code}\na <- 45.84\nb <- 858L\nc <- TRUE\nd <- 89 + 34i\ne <- 'abc'\n```\n:::\n\n\n### 1. Examine the data type at a low-level with `typeof()`\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntypeof(a)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"double\"\n```\n:::\n\n```{.r .cell-code}\ntypeof(b)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"integer\"\n```\n:::\n\n```{.r .cell-code}\ntypeof(c)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"logical\"\n```\n:::\n\n```{.r .cell-code}\ntypeof(d)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"complex\"\n```\n:::\n\n```{.r .cell-code}\ntypeof(e)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"character\"\n```\n:::\n:::\n\n\n### 2. Examine the data type at a high-level with `class()`\n\n\n::: {.cell}\n\n```{.r .cell-code}\nclass(a)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"numeric\"\n```\n:::\n\n```{.r .cell-code}\nclass(b)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"integer\"\n```\n:::\n\n```{.r .cell-code}\nclass(c)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"logical\"\n```\n:::\n\n```{.r .cell-code}\nclass(d)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"complex\"\n```\n:::\n\n```{.r .cell-code}\nclass(e)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"character\"\n```\n:::\n:::\n\n\n### 3. Use the `is.____()` functions to determine the data type\n\nTo test whether the variable is of a specific type, we can use the `is.____()` functions.\n\nFirst, we test the variable `a` which is numeric.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nis.numeric(a)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] TRUE\n```\n:::\n\n```{.r .cell-code}\nis.integer(a)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] FALSE\n```\n:::\n\n```{.r .cell-code}\nis.logical(a)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] FALSE\n```\n:::\n\n```{.r .cell-code}\nis.character(a)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] FALSE\n```\n:::\n:::\n\n\nSecond, we test the variable `c` which is logical.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nis.numeric(c)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] FALSE\n```\n:::\n\n```{.r .cell-code}\nis.integer(c)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] FALSE\n```\n:::\n\n```{.r .cell-code}\nis.logical(c)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] TRUE\n```\n:::\n\n```{.r .cell-code}\nis.character(c)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] FALSE\n```\n:::\n:::\n\n\n## Converting between various data types\n\nTo convert between data types we can use the `as.____()` functions. These include: `as.Date()`, `as.numeric()`, and `as.factor()`. Additionally, other helpful functions include factor() which adds levels to the data and `nchar()` which provides the length of the data.\n\n### Examples\n\n\n::: {.cell}\n\n```{.r .cell-code}\nas.integer(a)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 45\n```\n:::\n\n```{.r .cell-code}\nas.logical(0)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] FALSE\n```\n:::\n\n```{.r .cell-code}\nas.logical(1)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] TRUE\n```\n:::\n\n```{.r .cell-code}\nnchar(e)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 3\n```\n:::\n:::\n", | ||
"supporting": [], | ||
"filters": [ | ||
"rmarkdown/pagebreak.lua" | ||
], | ||
"includes": {}, | ||
"engineDependencies": {}, | ||
"preserve": {}, | ||
"postProcess": true | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
_freeze/posts/r_rstudio_basics/arithmetic/arithmetic/execute-results/html.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"hash": "24c6f9027f439b1d4fed6b1a287db4d2", | ||
"result": { | ||
"markdown": "---\ntitle: \"The Basics of R and RStudio\"\nsubtitle: \"Part 1: Simple Arithmetic\"\nauthor: \"William Okech\"\ndate: \"2022-06-15\"\nimage: \"r_and_rstudio.png\"\ncategories: [RStudio, R, Tutorial, Blog]\ntoc: true\ndraft: false\n---\n\n\n## Introduction\n\nThis is the first in a series of blog posts looking at the basics of R and RStudio. These programs allow us to perform various basic and complex calculations.\n\nTo get started, first, we will open R or RStudio. In R, go to the console, and in RStudio, head to the console pane. Next, type in a basic arithmetic calculation such as \"1 + 1\" after the angle bracket (\\>) and hit \"Enter.\"\n\nAn example of a basic calculation:\n\n\n::: {.cell}\n\n```{.r .cell-code}\n1+1\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 2\n```\n:::\n:::\n\n\nThe output will be observed next to the square bracket containing the number 1 (\\[1\\]).\n\n{fig-align=\"center\" width=\"90%\"}\n\nAdditionally, to include comments into the code block we use the hash (#) symbol. Anything written after the code block will be commented out and not run.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# A simple arithmetic calculation (which is not run because of the hash symbol)\n1+1\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 2\n```\n:::\n:::\n\n\n## Arithmetic operators available in R/RStudio\n\nVarious arithmetic operators (listed below) can be used in R/RStudio.\n\n| Arithmetic Operator | Description |\n|:-------------------:|:----------------------------------:|\n| \\+ | Addition |\n| \\- | Subtraction |\n| \\* | Multiplication |\n| / | Division |\n| \\*\\* or \\^ | Exponentiation |\n| %% | Modulus (remainder after division) |\n| %/% | Integer division |\n\n## Examples\n\n### Addition\n\n\n::: {.cell}\n\n```{.r .cell-code}\n10+30\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 40\n```\n:::\n:::\n\n\n### Subtraction\n\n\n::: {.cell}\n\n```{.r .cell-code}\n30-24\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 6\n```\n:::\n:::\n\n\n### Multiplication\n\n\n::: {.cell}\n\n```{.r .cell-code}\n20*4\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 80\n```\n:::\n:::\n\n\n### Division\n\n\n::: {.cell}\n\n```{.r .cell-code}\n93/4\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 23.25\n```\n:::\n:::\n\n\n### Exponentiation\n\n\n::: {.cell}\n\n```{.r .cell-code}\n3^6\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 729\n```\n:::\n:::\n\n\n### Modulus (remainder with division)\n\n\n::: {.cell}\n\n```{.r .cell-code}\n94%%5\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 4\n```\n:::\n:::\n\n\n### Integer Division\n\n\n::: {.cell}\n\n```{.r .cell-code}\n54%/%7\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 7\n```\n:::\n:::\n\n\n### Slightly more complex arithmetic operations\n\n\n::: {.cell}\n\n```{.r .cell-code}\n5-1+(4*3)/16*3\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 6.25\n```\n:::\n:::\n", | ||
"supporting": [], | ||
"filters": [ | ||
"rmarkdown/pagebreak.lua" | ||
], | ||
"includes": {}, | ||
"engineDependencies": {}, | ||
"preserve": {}, | ||
"postProcess": true | ||
} | ||
} |
Oops, something went wrong.