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.

Submit your lab to the corresponding assignment on Canvas. You have unlimited attempts before the deadline. Your final submission before the deadline will be graded.


Grading

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:

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.

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:


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:


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.