Disclaimer: The content of this RMarkdown note came from a course called Introduction to R for Finance in datacamp.
Numeric: Numbers Character: Strings or text Logical: TRUE or FALSE
You would use the numerical data type to show decimals like 3.1
Vectors, matricies, data frames, Lists, and factors
Vectors are a collection of data that are all the same type, whereas a matrix is a series of rows and columns that, like vectors, can only hold one data type.
Both can only hold 1 data type, but a matrix shows the data in a table format, where the vector just displays the data in the order it was inputted.
A matrix is a series of rows and columns that can only hold one data type, and a data frame is used to store a table of data and is nothing more than a grouping of rows and columns, but unlike vectors and matrixes, it can hold more than one data type.
Matricies and data frames both display data in a table format but unlike matricies, data frames can hold multiple data types
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 Monday 1
## 2 Tuesday 2
## 3 Wednesday 3
## 4 Thursday 4
## 5 Friday 5
Subset rows with daily returns greater than or equal to 4%.
## days returns
## 4 Thursday 4
## 5 Friday 5