Question: Question 6 : Sequences 1 . Use the seq ( ) function to create a sequence of numbers ranging from 0 to 1 in steps
Question : Sequences
Use the seq function to create a sequence of numbers ranging from to in steps of this is also
a vector by the way and assign this sequence to a variable called seq
Next, create a sequence from to in steps of and assign to a variable called seqHint: you
may find it easier to include the rev function in your code
Ok just for fun, run the following code which shows how we can create all different kinds of patterns using
the rep function such as:
aaaccceeeggg
acegacegaceg
sevens, twos, eight and ones
rep: times
repcaceg each
repcaceg times
rep: each times
rep: times :
repc times c
Question : Ordering
Say we have three kids John Jack, and Jane that are and inches respectively. We can apply the
following code to order the heights from shortest to tallest and use those results to sort the names based on
the height. Consequently, we can see that Jack is the shortest followed by Jane and then John.
# names and heights of kids
childnames cJohn "Jack", "Jane"
ht c
# get the indexes of the heights, smallest to tallest and sort the names based
# on these indexes
heightord orderht
namessort childnamesheightord
namessort
## "Jack" "Jane" "John"
Knowing this, apply this same procedure to a larger group of kids.
Create a vector of childnames and hts in inches for the following children:
Alfred:
Barbara:
James:
Jane:
John:
Judy:
Louise:
Mary:
Ronald:
William:
Who is the shortest?
Who is the tallest child?
If you lined up these kids based on their height, which kids would be standing next to Alfred?
Question : Missing values
Almost there! In R missing values are usually represented with an NA Missing data can be tricky to deal
with in R and in statistics more generally and cause some surprising behavior when using some functions.
To explore this a little further lets create a vector called mydata with the values NA
Notice the value of the th element of mydata is missing and represented with an NA Now use the mean
function to calculate the mean of the values in mydata. What does R return? Confused? Next, take a look
at the help page for the function mean Can you figure out how to alter your use of the mean function
to calculate the mean without this missing value?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
