Heyyy guys!
I’m guessing ya’ll are chilling and have familiarized yourselves with the basics of R which we discussed last week. Hopefully, it wasn’t so difficult to understand. If you need help understanding anything, remember to shoot me an email.
Alright, this week we would be learning Vectors. Not Vector the singer, Vector the one dimensional array which holds different kinds of characters. You create this using the combine function. c( ).
Guys, I’m not on my laptop, so I would be using a resource that I think we can all use as well: https://www.datacamp.com/courses/free-introduction-to-r
Example:
Using # when writing in any python or R is used to make a comment. Below I have assigned winnings or losses to Poker vector and roulette vector, I have converted both games into a matrix and I have assigned names to the rows and columns. Â
Result:
To assign to the columns, you can also use names()
In adding vectors, It is important to know that the below are similar:
c(1, 2, 3) + c(4, 5, 6) or c(1 + 4, 2 + 5, 3 + 6) would both give you ===> c(5, 7, 9)
you can also add the objects which contain the variables or represent the vectors
Result:
A_vector <- c(1, 2, 3)
B_vector <- c(4, 5, 6)
total_vector <- c (A_vector + B_vector)
Going back to the first example, lets calculate how much we made from poker_vector, roulette_vector and the entire game using (+) and Sum() functions.
Result:
Whoop! I hope this wasn’t too intense. I would let us practice on this for now. Next week, we would go deeper. As always, share your concerns, worries, questions in the comment section. You can also shoot an email to Seyitan.awojobi@gmail.com if you need anything.
Cheers,
Oluwaseyitan.