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.
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.
In this exercise we will create, but not store, several vectors. Write code that creates the following vectors:
3.14. Give the elements names
FALSErepeated 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!
Create a matrix named
c_matrix that stores the integers from
100 arranged by column. (That is, the first column will contain
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.
?matrixto read the documentation.
Run and include the following code in your
Create but do not store a list containing the following elements:
xwhich contains only the numeric (double or integer) value 42.
ywhich has 5 rows and 2 columns. It can contain any values.
zthat contains the months of the year, that is
February, etc. Hint: Run
Create the following data frame with the name
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:
Also include that code in your
pokedex_numvector is integers.
type_secondaryvector can be created with
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
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.