Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 6 : Sequences 1 . Use the seq ( ) function to create a sequence of numbers ranging from 0 to 1 in steps

Question 6: Sequences
1. Use the seq() function to create a sequence of numbers ranging from 0 to 1 in steps of 0.1(this is also
a vector by the way) and assign this sequence to a variable called seq1.
2. Next, create a sequence from 10 to 1 in steps of 0.5 and assign to a variable called seq2(Hint: 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:
123123123
aaaccceeeggg
acegacegaceg
111222333111222333
111112222333445
4 sevens, 3 twos, 1 eight and 5 ones
rep(1:3, times =3)
rep(c("a","c","e","g"), each =3)
rep(c("a","c","e","g"), times =3)
rep(1:3, each =3, times =2)
rep(1:5, times =5:1)
rep(c(7,2,8,1), times = c(4,3,1,5))
Question 7: Ordering
Say we have three kids (John, Jack, and Jane) that are 63,59, and 60 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 3 kids
child_names <- c("John", "Jack", "Jane")
ht <- c(63,59,60)
# get the indexes of the heights, smallest to tallest and sort the names based
# on these indexes
height_ord <- order(ht)
names_sort <- child_names[height_ord]
names_sort
## [1] "Jack" "Jane" "John"
Knowing this, apply this same procedure to a larger group of kids.
1. Create a vector of child_names and hts (in inches) for the following 10 children:
1. Alfred: 62
2. Barbara: 58
3
3. James: 61
4. Jane: 61
5. John: 59
6. Judy: 64
7. Louise: 63
8. Mary: 61
9. Ronald: 60
10. William: 62
2. Who is the shortest?
3. Who is the tallest child?
4. If you lined up these kids based on their height, which kids would be standing next to Alfred?
Question 8: 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 2,4,1,6,8,5, NA,4,7.
Notice the value of the 7th 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

Evaluate different organizational structures

Answered: 1 week ago

Question

Does the duty to accommodate apply in this case?

Answered: 1 week ago