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.

R’s three most basic data types are: numeric, logical, and character. Decimal numbers like 3.1 are an example of a numeric data type.

Question 2

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

R’s five common types of objects are: a vector, a matrix, a factor, a data frame, and a list.

2.a.

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

A vector is a collection of data that are all the same type. A matrix consists of rows and columns and has the same data type. A vector and a matrix are similar b/c they consist of the same data type. They are different b/c a matrix consists of rows and columns and a vector consists of a row or a column.

2.b

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

A matrix consists of rows and columns and has the same data type. A data frame is used to store data and has rows and columns. Similar to matrix b/c of rows and columns. Different b/c data frames can have multiple data types in the same frame.

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 Tues       2
## 3  Wed       3
## 4  Thu       4
## 5  Fri       5

Question 4

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

##   days returns
## 4  Thu       4
## 5  Fri       5