Skip to content

Commit

Permalink
Merge pull request #101 from jhudsl/transfer-intro-to-r-class
Browse files Browse the repository at this point in the history
Transfer intro to r class
  • Loading branch information
avahoffman authored May 23, 2022
2 parents 05bda27 + 30f2c07 commit 7638be0
Show file tree
Hide file tree
Showing 260 changed files with 64,784 additions and 56,482 deletions.
18 changes: 13 additions & 5 deletions Basic_R/Basic_R.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ print("I'm code")
6 / 2 * (1 + 2)


## ---- fig.alt="Problem gives answer of 1 or 9 depending on calculator.", out.width = "30%", echo = FALSE, out.extra='style="float:left"'----
knitr::include_graphics("../images/Basic_R_calculator.jpg")


## ---- fig.alt="Problem gives answer of 1 or 9 depending on calculator.", out.width = "60%", echo = FALSE, out.extra='style="float:left"'----
knitr::include_graphics("../images/Basic_R_viral_math_problem.png")


## -----------------------------------------------------------------------------
# this is a comment

Expand All @@ -32,21 +40,21 @@ print("I'm code")


## ----assign-------------------------------------------------------------------
x = 2 # Same as: x <- 2
x <- 2
x
x * 4
x + 2


## ----assignClass--------------------------------------------------------------
class(x)
y = "hello world!"
y <- "hello world!"
print(y)
class(y)


## ----myName-------------------------------------------------------------------
name = "Ava Hoffman"
name <- "Ava Hoffman"
name


Expand All @@ -57,7 +65,7 @@ class(x)


## ----myName2------------------------------------------------------------------
name2 = c("Ava","Hoffman")
name2 <- c("Ava","Hoffman")
name2


Expand All @@ -83,7 +91,7 @@ name2 + 4


## ----assign5------------------------------------------------------------------
y = x + c(1, 2, 3, 4)
y <- x + c(1, 2, 3, 4)
y


Expand Down
181 changes: 98 additions & 83 deletions Basic_R/Basic_R.html

Large diffs are not rendered by default.

Binary file modified Basic_R/Basic_R.pdf
Binary file not shown.
18 changes: 13 additions & 5 deletions Basic_R/index.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ print("I'm code")
6 / 2 * (1 + 2)


## ---- fig.alt="Problem gives answer of 1 or 9 depending on calculator.", out.width = "30%", echo = FALSE, out.extra='style="float:left"'----
knitr::include_graphics("../images/Basic_R_calculator.jpg")


## ---- fig.alt="Problem gives answer of 1 or 9 depending on calculator.", out.width = "60%", echo = FALSE, out.extra='style="float:left"'----
knitr::include_graphics("../images/Basic_R_viral_math_problem.png")


## -----------------------------------------------------------------------------
# this is a comment

Expand All @@ -32,21 +40,21 @@ print("I'm code")


## ----assign-------------------------------------------------------------------
x = 2 # Same as: x <- 2
x <- 2
x
x * 4
x + 2


## ----assignClass--------------------------------------------------------------
class(x)
y = "hello world!"
y <- "hello world!"
print(y)
class(y)


## ----myName-------------------------------------------------------------------
name = "Ava Hoffman"
name <- "Ava Hoffman"
name


Expand All @@ -57,7 +65,7 @@ class(x)


## ----myName2------------------------------------------------------------------
name2 = c("Ava","Hoffman")
name2 <- c("Ava","Hoffman")
name2


Expand All @@ -83,7 +91,7 @@ name2 + 4


## ----assign5------------------------------------------------------------------
y = x + c(1, 2, 3, 4)
y <- x + c(1, 2, 3, 4)
y


Expand Down
37 changes: 21 additions & 16 deletions Basic_R/index.Rmd
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
title: "Variables: Objects in R"
title: "Basic R"
output:
ioslides_presentation:
css: ../styles.css
widescreen: yes
subtitle: Basic R Functionality
---

```{r, echo = FALSE}
Expand All @@ -15,16 +14,14 @@ opts_chunk$set(comment = "")
## Common new users frustations

1. **Different versions of software**
1. **Data type problems (is that a string or a number?)**
1. **Data type problems (is that a character or a number?)**
2. Working directory problems: trying to read files that R "can't find"
- RStudio can help, and so do RStudio Projects
- discuss in Data Input/Output lecture
3. Typos (R is **case sensitive**, `x` and `X` are different)
- RStudio helps with "tab completion"
- discussed throughout

For more on the most common errors and how to debug them read [this guide from the Childhood Cancer Data Lab](https://github.com/AlexsLemonade/training-modules/blob/master/intro-to-R-tidyverse/00b-debugging_resources.md).

<!-- ## Getting Started -->

<!-- * You should have the latest version of R installed! -->
Expand Down Expand Up @@ -73,15 +70,15 @@ So `print("I'm code")` is the code chunk and [1] "I'm code" is the output.
2 ^ 3
```

Note, when you type your command, R inherently thinks you want to print the result.
Note, when you type your command, R inherently thinks you want to print the result.

## R as a calculator

* The R console is a full calculator
* Try to play around with it:
* +, -, /, * are add, subtract, divide and multiply
* ^ or ** is power
* parentheses -- ( and ) -- work with order of operations
* parentheses -- ( and ) -- work with order of operations
* %% finds the remainder

## R as a calculator
Expand All @@ -92,6 +89,14 @@ Note, when you type your command, R inherently thinks you want to print the resu
6 / 2 * (1 + 2)
```

```{r, fig.alt="Problem gives answer of 1 or 9 depending on calculator.", out.width = "30%", echo = FALSE, out.extra='style="float:left"'}
knitr::include_graphics("../images/Basic_R_calculator.jpg")
```

```{r, fig.alt="Problem gives answer of 1 or 9 depending on calculator.", out.width = "60%", echo = FALSE, out.extra='style="float:left"'}
knitr::include_graphics("../images/Basic_R_viral_math_problem.png")
```

## R as a calculator

Try evaluating the following:
Expand All @@ -100,7 +105,7 @@ Try evaluating the following:
* `2 * 3 / 4 * 2`
* `2^4 - 1`

## Commenting
## Commenting in Scripts

`#` is the comment symbol

Expand All @@ -117,10 +122,10 @@ Try evaluating the following:
```


## R variables
## R variables

* You can create variables from within the R environment and from files on your computer
* R uses "<-" to assign values to a variable name
* R uses "<-" to assign values to a variable name (you can also use "=" but this is less accepted)
* Variable names are case-sensitive, i.e. X and x are different

```{r assign}
Expand All @@ -133,7 +138,7 @@ x + 2
## R variables

* The most comfortable and familiar class/data type for many of you will be `data.frame`
* You can think of these as essentially Excel spreadsheets with rows (usually subjects or observations) and columns (usually variables)
* You can think of these as essentially spreadsheets with rows (usually subjects or observations) and columns (usually variables)

## R variables

Expand All @@ -157,13 +162,13 @@ Try assigning your full name to an R variable called `name`
Try assigning your full name to an R variable called `name`

```{r myName}
name <- "Candace Savonen"
name <- "Ava Hoffman"
name
```

## The 'combine' function

The function `c()` collects/combines/joins single R objects into a vector of R objects. It is mostly used for creating vectors of numbers, character strings, and other data types.
The function `c()` collects/combines/joins single R objects into a vector of R objects. It is mostly used for creating vectors of numbers, character strings, and other data types.

```{r assign3a}
x <- c(1, 4, 6, 8)
Expand Down Expand Up @@ -223,7 +228,7 @@ x + c(1, 2, 3, 4)

## Lab Part 1

[Website](http://jhudatascience.org/intro_to_r/index.html)
[Website](http://jhudatascience.org/intro_to_R_class/index.html)

## R variables

Expand All @@ -239,7 +244,7 @@ Save these modified vectors as a new vector.

```{r assign5}
y <- x + c(1, 2, 3, 4)
y
y
```

Note that the R object `y` is no longer "Hello World!" - It has effectively been overwritten by assigning new data to the variable
Expand All @@ -264,4 +269,4 @@ This tells you that `x` is a numeric vector and tells you the length.

## Lab Part 2

[Website](http://jhudatascience.org/intro_to_r/index.html)
[Website](http://jhudatascience.org/intro_to_R_class/index.html)
181 changes: 98 additions & 83 deletions Basic_R/index.html

Large diffs are not rendered by default.

36 changes: 22 additions & 14 deletions Basic_R/lab/Basic_R_Lab.R
Original file line number Diff line number Diff line change
@@ -1,55 +1,63 @@
## ----setup, include=FALSE---------------------------------------------------------
## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(echo = TRUE)


## ---------------------------------------------------------------------------------
## -----------------------------------------------------------------------------
# my.num <- ???



## ---------------------------------------------------------------------------------
## -----------------------------------------------------------------------------



## ---------------------------------------------------------------------------------
## -----------------------------------------------------------------------------
# my.char <- ???



## ---------------------------------------------------------------------------------
## -----------------------------------------------------------------------------



## ---------------------------------------------------------------------------------
## -----------------------------------------------------------------------------



## ---------------------------------------------------------------------------------
## -----------------------------------------------------------------------------



## ---- error=TRUE------------------------------------------------------------------
## ---- error=TRUE--------------------------------------------------------------



## ---------------------------------------------------------------------------------
## -----------------------------------------------------------------------------



## ---------------------------------------------------------------------------------
## -----------------------------------------------------------------------------



## ---------------------------------------------------------------------------------
## -----------------------------------------------------------------------------
z <- y[1:5]
# ???



## ---------------------------------------------------------------------------------
## -----------------------------------------------------------------------------



## ---------------------------------------------------------------------------------
## -----------------------------------------------------------------------------
# ? <- c(?, ???)


## -----------------------------------------------------------------------------

## ---------------------------------------------------------------------------------


## -----------------------------------------------------------------------------


Loading

0 comments on commit 7638be0

Please sign in to comment.