R Studio Project

1. R Basics##################
“`{r}
# Q1. What is two to the power of five?
“`
“`{r}
# Q2. Create a vector called stock_prices with the following data points: 23,27,23,21,34
# output: 23 27 23 21 34
“`
“`{r}
# Q3. Assign names to the price data points relating to the day of the week, starting with Mon,
Tue, Wed, etc…
# Output:
# Mon Tues Wed Thu Fri
# 23 27 23 21 34
“`
“`{r}
# Q4. Create a vector called over_23 consisting of logicals that correspond to the days where
the stock price was more than $23
# Output:
# Mon Tues Wed Thu Fri
#FALSE TRUE FALSE FALSE TRUE
“`
“`{r}
#Q5. Create a 4×3 matrix with values from 1 to 12
# output:
#
[,1] [,2] [,3]
# [1,] 1 2 3
# [2,] 4 5 6
# [3,] 7 8 9
# [4,] 10 11 12
“`
“`{r}
#Q6. multiple the matrix created in Q5 by 10.
# output:
#
[,1] [,2] [,3]
# [1,] 10 20 30
# [2,] 40 50 60
# [3,] 70 80 90
# [4,] 100 110 120
“`
#################################
2. Conditional Statement
#################################
“`{r}
# Q1. Write a script that prints “use the force!” if the variable x is equal to 1
# hint: create a variable and assign 1 to it. Then create an if statement.
# Try the if statement yourself using a different value for x.
# output: [1] “use the force!”
“`
“`{r}
# Q2. Write a script that will print “To infinity and beyond!” if the variable y is an even number.
# Othewise, print “Meditate on this, I will”
# Try different values of y.
# output depends on input number:
# [1] “To infinity and beyond!”
# [1] “Meditate on this, I will”
“`
##################
3. Matrix
##################
“`{r}
# Q1 Create a 2 x 3 matrix with values from 1 to 6, populated horizontally.
# output:
#
[,1] [,2] [,3]
# [1,] 1 2 3
# [2,] 4 5 6
“`
“`{r}
# Q3. confirm that mat is a matrix using is.matrix()
# output: TRUE
“`
“`{r}
# Q4. Create a 5 by 5 matrix consisting of the numbers 1-25 and assign it to the
# name mat2.
# output: The top row should be the numbers 1-5.
“`
“`{r}
# Q5. Using index notation, grab the lower right 3×3 sub-martix of mat2
# output:
# [,1] [,2] [,3]
#[1,] 13 14 15
#[2,] 18 19 20
#[3,] 23 24 25
“`
“`{r}
# Q6. Using index notation, grab the sub-section of mat2 below
# output:
# [,1] [,2]
#[1,] 7 8
#[2,] 12 13
“`
“`{r}
# Q7. What is the sum of all the elements in mat2?
# output: 325
“`
######################
4. Data Frame
######################
“`{r}
# Q1. Load the data set “statex77.csv”
# Assign it to df
# No output
df

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER