Skip to content
Course Notes: Introduction to R
Course Notes
Use this workspace to take notes, store code snippets, or build your own interactive cheatsheet! For courses that use data, the datasets will be available in the datasets
folder.
# Import any packages you want to use here
Take Notes
Add notes here about the concepts you've learned and code cells with code you want to keep.
Wow. Vector arithmetic in R is so simple compared to Python. It's truly...beautiful. A small note...well I suppose the code snippets should go below this text box. I'm quite pleased and excited with how casual it is to perform complex measures in this language though. Literally what would take many lines of code or specialized libraries in other languages.
# Examples vector arithmetic because it's so damn cool :)
x <- c(21, 300, -453, 23194, 23, 48, -3)
y <- c(299, 529, -545, 2945, -12308, -34, 100) #I believe the numbers need to be equal in total within the "list"
# The below code can be "wrapped" around any variable I want to apply the days to
days_of_the_week <- c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
names(x) <- days_of_the_week
names(y) <- days_of_the_week
# Now for some arithmetic
Addition <- x + y
Subtraction <- x - y
Multiplication <- x * y
Division <- x / y
print("X")
print(x)
print("Y")
print(y)
print("First let's do addition")
print(Addition)
print("Time for subtraction")
print(Subtraction)
print("Now we gotta go ahead and do our multiplication")
print(Multiplication)
print("And finally, the great, the lovely, division")
print(Division)