Skip to content

Commit

Permalink
Merge pull request #499 from jhudsl/input-updates-post-jan-24
Browse files Browse the repository at this point in the history
POST CLASS UPDATE: Data Import and Basic R
  • Loading branch information
avahoffman authored Mar 14, 2024
2 parents d2d3267 + fd60b51 commit 289b768
Show file tree
Hide file tree
Showing 8 changed files with 37,575 additions and 37,516 deletions.
74,546 changes: 37,273 additions & 37,273 deletions data/vaccinations.csv

Large diffs are not rendered by default.

13 changes: 0 additions & 13 deletions modules/Basic_R/Basic_R.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -337,23 +337,10 @@ str(y)

This tells you that `x` is a numeric vector and tells you the length.

## R objects

This is handy when we start dealing with bigger / more complex objects.

```{r include=FALSE}
z <- sample(y, size = 100, replace = T)
```

```{r}
str(z)
```

## Lab Part 2

- Reassigning allows you to make changes "in place"
- `str()` tells you a lot of information about an object in your environment
- `sample()` creates a random sample of values

💻 [Lab](https://jhudatascience.org/intro_to_r/modules/Basic_R/lab/Basic_R_Lab.Rmd)

Expand Down
78 changes: 56 additions & 22 deletions modules/Basic_R/lab/Basic_R_Lab.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Remember anything you type here can be "sent" to the console with Cmd-Enter (OS-

# Part 1

1\. Create a new object called `my.num` that contains 6 numbers.
### 1.1

Create a new object called `my.num` that contains 6 numbers.

```
# General format
Expand All @@ -27,15 +29,17 @@ my.num <- c(number1, number2, ...)
```

### 1.2

2\. Multiply `my.num` by 4.
Multiply `my.num` by 4.

```{r}
```

### 1.3

3\. Create a second object called `my.char` that contains 5 character strings.
Create a second object called `my.char` that contains 5 character strings.

```
# General format
Expand All @@ -46,29 +50,36 @@ my.char <- c("character1", "character2", ...)
```

### 1.4

4\. Combine the two objects `my.num` and `my.char` into an object called `both`.
Combine the two objects `my.num` and `my.char` into an object called `both`.

```{r}
```

### 1.5

5\. What is the length of `both`? Use the `length()` function.
What is the length of `both`? Use the `length()` function.

```{r}
```

### 1.6

6\. What class is `both`?
What class is `both`?

```{r}
```


**Bonus / Extra practice**: Create a vector that contains 4 sets of the numbers 1, 2, 3, and 4.
# Practice on Your Own!

### P.1

Create a vector that contains 4 sets of the numbers 1, 2, 3, and 4.

```{r}
Expand All @@ -77,26 +88,30 @@ my.char <- c("character1", "character2", ...)

# Part 2

7\. Divide `both` by 3, what happens?
### 2.1

Divide `both` by 3, what happens?

```{r, error=TRUE}
```

### 2.2

8\. Create a vector with elements 1, 2, 3, 4, 5 and call it `x`.
Create a vector with elements 1, 2, 3, 4, 5 and call it `x`.

```
# General format
x <- c(...)
```

```{r}
```

### 2.3

9\. Create another vector with elements 10, 20, 30, 40, 50 and call it `y`.
Create another vector with elements 10, 20, 30, 40, 50 and call it `y`.

```
# General format
Expand All @@ -107,15 +122,17 @@ y <- c(...)
```

### 2.4

10\. Determine the length of `x` and `y`. Next, add them together.
Determine the length of `x` and `y`. Next, add the vectors x and y together.

```{r}
```

### 2.5

11\. Append the value 60 onto the vector `y` (hint: you can use the `c()` function).
Append the value 60 onto the vector `y` (hint: you can use the `c()` function).

```
# General format
Expand All @@ -126,32 +143,41 @@ y <- c(y, ...)
```

### 2.6

12\. Determine the length of `x` and `y`.
Determine the length of `x` and `y`.

```{r}
```

### 2.7

13\. Add `x` and `y` together. What happens?
Add `x` and `y` together. What happens?

```{r}
```


**Bonus / Extra practice**: Multiply the following `a` and `b` together. How is this similar to the way R performs addition in #10 ?
# Practice on Your Own!

### P.2

Multiply the following `a` and `b` together. How is this similar to the way R performs addition in #10 ?

```{r}
a <- c(1, 2, 3)
b <- c(10, 100, 1000)
```


# Part 3

14\. Create a vector object called `int_vect` that starts at 1 and goes up to 10. Use `seq()`.
### 3.1

Create a vector object called `int_vect` that starts at 1 and goes up to 10. Use `seq()`.

```
# General format
Expand All @@ -162,8 +188,9 @@ seq(from = NUMBER, to = NUMBER)
```

### 3.2

15\. Repeat the `int_vect` object this sequence 3 times using `rep()` and store the new object as `int_vect_3`.
Repeat the `int_vect` object this sequence 3 times using `rep()` and store the new object as `int_vect_3`.

```
# General format - times and each are optional
Expand All @@ -174,29 +201,36 @@ rep(x = OBJECT_TO_REPEAT, times = NUM_TIMES_TO_REPEAT, each = NUM_TIMES_TO_REPEA
```

### 3.3

16\. What is the length of `int_vect_3`?
What is the length of `int_vect_3`?

```{r}
```

### 3.4

17\. Create a vector that takes the sequence "Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree" and repeats each element 10 times.
Create a vector that takes the sequence "Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree" and repeats each element 10 times.

```{r}
```


**Bonus / Extra practice**: "Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree" are often responses to surveys. Create a randomly sampled vector of 30 survey responses. (hint use `sample()` and set the replace argument to `TRUE`). Store the output as `my_responses`. Examine the data by typing the name `my_responses` in the Console.
# Practice on Your Own!

### P.3

"Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree" are often responses to surveys. Create a randomly sampled vector of 30 survey responses. (hint use `sample()` and set the replace argument to `TRUE`). Store the output as `my_responses`. Examine the data by typing the name `my_responses` in the Console.

```{r}
```

### P.4

**Bonus / Extra practice**: Let's say you change your survey so participants can rank their response 1-10 (inclusive). Create a randomly sampled vector of 30 survey responses. (hint use `seq()` and `sample()` and set the replace argument to `TRUE`). Store the output as `my_responses_2`. Examine the data by typing the name `my_responses_2` in the Console.
Let's say you change your survey so participants can rank their response 1-10 (inclusive). Create a randomly sampled vector of 30 survey responses. (hint use `seq()` and `sample()` and set the replace argument to `TRUE`). Store the output as `my_responses_2`. Examine the data by typing the name `my_responses_2` in the Console.

```{r}
Expand Down
Loading

0 comments on commit 289b768

Please sign in to comment.