5.3 Test your R might!
Create the vector [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] in three ways: once using
c()
, once usinga:b
, and once usingseq()
.Create the vector [2.1, 4.1, 6.1, 8.1] in two ways, once using
c()
and once usingseq()
Create the vector [0, 5, 10, 15] in 3 ways: using
c()
,seq()
with aby
argument, andseq()
with alength.out
argument.Create the vector [101, 102, 103, 200, 205, 210, 1000, 1100, 1200] using a combination of the
c()
andseq()
functionsA new batch of 100 pirates are boarding your ship and need new swords. You have 10 scimitars, 40 broadswords, and 50 cutlasses that you need to distribute evenly to the 100 pirates as they board. Create a vector of length 100 where there is 1 scimitar, 4 broadswords, and 5 cutlasses in each group of 10. That is, in the first 10 elements there should be exactly 1 scimitar, 4 broadswords and 5 cutlasses. The next 10 elements should also have the same number of each sword (and so on).
Create a vector that repeats the integers from 1 to 5, 10 times. That is [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, …]. The length of the vector should be 50!
Now, create the same vector as before, but this time repeat 1, 10 times, then 2, 10 times, etc., That is [1, 1, 1, …, 2, 2, 2, …, … 5, 5, 5]. The length of the vector should also be 50
Create a vector containing 50 samples from a Normal distribution with a population mean of 20 and standard deviation of 2.
Create a vector containing 25 samples from a Uniform distribution with a lower bound of -100 and an upper bound of -50.