title: “Quiz on Introduction to R” author: “Maegan Howe” output: html_document: toc: true —
Disclaimer: The content of this RMarkdown note came from a course called Introduction to R for Finance in datacamp.
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 types of data types are numeric, character and logical.The decimal 3.1 would belong to the numeric data type.
What are R’s five most common types of objects? Type your answer below.
The 5 most common types of R objects include: a vector, matrix, factor, data frame, and list.
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 row and columns and has the same data type. The difference is that a vector can be either a row OR andf coloumn however it can’t have both, while a matrix can have BOTH rows AND columns. They are similar in the way that they both contain rows and columns.
Compare matrices and data frames. What are similarities and differences? Type your answer below.
A matrix consists of row and columns and has the same data type. A data frame is used to store data and consists or rows and columns. They both contain rows and columns however a data frame can consist pf multiple data types in the same frame while a matrix cannot.
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 Thurs 4
## 5 Fri 5
Subset rows with daily returns greater than or equal to 4%.
## days returns
## 4 Thurs 4
## 5 Fri 5