Instructions: Paste your code from the console in the gray boxes below.

Part 1

1.1

Create a new object called my.num that contains any number.

# General format
my.num <- ?

1.2

Multiply my.num by 4.

1.3

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

# General format
my.char <- c("character1", "character2", ...)

1.4

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

1.5

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

1.6

What class is both?

1.7

Divide both by 3, what happens?

Practice on Your Own!

P.1

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

Part 2

2.1

Create a vector with elements 1, 10, 100, 1000 and call it z.

# General format
z <- c(...)

2.2

Multiply each number in z by 5.

2.3

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

# General format
seq(from = NUMBER, to = NUMBER)

2.4

What is the length of int_vect?

2.5

Install the tidyverse package using install.packages("tidyverse"). Load this package using library(tidyverse).

Practice on Your Own!

P.2

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

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

P.3

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

# General format
y <- c(...)

P.4

Determine the length of x and y. Next, add the vectors x and y together.

P.5

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

# General format
y <- c(y, ...)

P.6

Determine the length of x and y.

P.7

Add x and y together. What happens?

P.8

Multiply the following a and b together. How is this similar to the way R performs addition in question 2.6 ?

a <- c(1, 2, 3)
b <- c(10, 100, 1000)

P.9

Create a vector that takes the sequence “Strongly Agree”, “Agree”, “Neutral”, “Disagree”, “Strongly Disagree” and repeats each element 10 times.

P.10

“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.

P.11

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.