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.

Three most data types of R are Numeric, Character, and Logical. Decimal numbers like 3.1 would be numeric.

Question 2

What are R’s five most common types of objects? Type your answer below.

R’s five most common types of objects are vectors, matrices, data frames, factors, and lists.

2.a.

Compare vectors and matrices. What are similarities and differences? Type your answer below.

Vectors and matrices are both similar in that they are both data structures that deal with one type of data. For example, a vector or a matrix can only deal with numeric or character data, and cannot mix both or else the superior data type will coerce the other. The difference is that vectors are one dimensional while matrices are two dimensional. Vectors are a row and matrices have rows and columns.

2.b

Compare matrices and data frames. What are similarities and differences? Type your answer below.

The similarities between matrices and data frames are that they are both data structures that are 2 dimensional. A data frame can hold more than one data 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.

##    days returns
## 1   Mon       1
## 2   Tue       2
## 3   Wed       3
## 4 Thurs       4
## 5   Fri       5

Question 4

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

##    days returns
## 4 Thurs       4
## 5   Fri       5