## Directions

For this lab, you will create a single .R file called lab02.R. The following exercises will ask you to write code. Place all requested code in this .R file separated by comments which indicate which code corresponds to which exercise.

• Note: Do not write your name or netID anywhere in the file or in the filename. To the best of our ability, we will try to grade labs anonymously.

This lab will largely be graded based on completion. For each exercise that you demonstrate a good-faith effort to complete, you will receive two points.

## Exercise 1 (Creating More Vectors)

In this exercise we will create, but not store, several vectors. Write code that creates the following vectors:

• A integer vector of the first nine Fibonacci numbers, starting from 0. Hint: Use the c() function.
• A double vector containing the numbers 42, 42, and 3.14. Give the elements names one, two, and three respectively.
• A character vector containing “University of Illinois at Urbana-Champaign” where each word is an element of the vector. (Urbana-Champaign being one word.)
• A logical vector containing the sequence TRUE, TRUE, FALSE repeated 10 times.

Place this code in your .R file for this exercise. Also, run your code to make sure it does what you expect and does not produce any errors!

## Exercise 2 (Creating A Matrix)

Create a matrix named c_matrix that stores the integers from 1 to 100 arranged by column. (That is, the first column will contain 1, 2, 3, etc.) The matrix should have 25 rows and 4 columns.

Also create a matrix named r_matrix that does the same thing, but arranged by row. It should also have 25 rows and 4 columns.

• Hint: Use the matrix() function. Use ?matrix to read the documentation.

Run and include the following code in your .R file.

c_matrix
r_matrix

## Exercise 3 (Creating Lists)

Create but do not store a list containing the following elements:

• A vector named x which contains only the numeric (double or integer) value 42.
• A matrix named y which has 5 rows and 2 columns. It can contain any values.
• A vector names z that contains the months of the year, that is January, February, etc. Hint: Run ?letters.

## Exercise 4 (First Generation Starter Pokemon)

Create the following data frame with the name starter_pokemon:

  pokedex_num       name type_primary type_secondary
1           1  Bulbasaur        Grass         Poison
2           2    Ivysaur        Grass         Poison
3           3   Venusaur        Grass         Poison
4           4 Charmander         Fire
5           5 Charmeleon         Fire
6           6  Charizard         Fire
7           7   Squirtle        Water
8           8  Wartortle        Water
9           9  Blastoise        Water               

After creating the data frame, run the code:

starter_pokemon

Also include that code in your .R file.

Some notes:

• The numbers along the left hand side are “row names.” There are automatically generated and can be ignored.
• The pokedex_num vector is integers.
• All other vectors are character typed. Note that the blanks in the type_secondary vector can be created with "".

## Exercise 5 (External Data)

The previous exercise is not how things work in the real world. In this exercise, you will run some code to import external data. You don’t need to write any code yourself. However, run the following code to see what it does! Also include it in your .R file.

pokemon = read.csv("https://stat385.org/data/pokemon.csv")
head(pokemon)
tail(pokemon)
pokemon[1:25, 1:4]
pokemon[pokemon\$legendary == TRUE, ]

We’ll talk about what some of this code does later, but see if you can already figure out what it does.