Disclaimer: The content of this RMarkdown note came from a course called Introduction to R for Finance in datacamp.

Question 1

What are R’s three most basic data types? Of the three, what would be decimal numbers like 3.1? Type your answer below. Character, numeric, integer. Decimal numbers such as 3.1 would be numeric. ## Question 2 What are R’s five most common types of objects? Type your answer below. Atomic Vector, list, matrix, data frame, factors. ### 2.a. Compare vectors and matrices. What are similarities and differences? Type your answer below. A vector is a collection of cells with a fixed size and a matrices is a two-dimensional vector. ### 2.b Compare matrices and data frames. What are similarities and differences? Type your answer below. A data frame is essentially a table where each column can hold a different cell type. A matrices can only hold one cell type. ## Question 3 Create a vector, “returns”, in place of “ret”; and assign 5 return values, 1 through 5 in place of (5, 2, 3, 7, 8, 3, 5, 9, 1, 4, 6, 3). Create another vector, “days”, in place of “months”; and assign 5 days, Monday through Friday in place of (“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”, “Dec”). Then, create a data frame, “daily_returns”, in place of “monthly_returns” by combining days and returns.

# Vectors of 12 days of returns, and day names
daily_returns <- c(1, 2, 3, 4, 5)
days <- c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday" )
#Create a data frame, daily_returns
daily_returns <- data.frame(days, daily_returns)

# Print out daily_returns
daily_returns
##        days daily_returns
## 1    Monday             1
## 2   Tuesday             2
## 3 Wednesday             3
## 4  Thursday             4
## 5    Friday             5

Question 4

Subset rows with daily returns greater than or equal to 4%.

# Subset rows with returns greater than or equal to 4%
subset(daily_returns, daily_returns >= 4)
##       days daily_returns
## 4 Thursday             4
## 5   Friday             5