PLEASE NUMBER EACH ANSWER Students will use advanced looping methods including replicate(), lapply(), sapply(), and apply(), and...

80.2K

Verified Solution

Question

Statistics

PLEASE NUMBER EACH ANSWER

Students will use advanced looping methods includingreplicate(), lapply(), sapply(), and apply(), and access datasetsprovided with R packages in an R script.

  1. The function call, rnorm(1), generates a normal random number.Use replicate() to generate 10 normal random numbers and assignthem to a vector called nums.
  2. The R statement, data(iris), loadsthe built-in R data set iris. This dataset has 150 rows and 5columns. The 5 column names are\"Sepal.Length\",\"Sepal.Width\",\"Petal.Length\",\"Petal.Width\" and\"Species\".
    1. Write R code(s) to return a list of 4 items that correspond tothe averages of the first 4 columns iniris. The contents of the list should beas follows:

      $Sepal.Length
      [1] 5.843333

      $Sepal.Width
      [1] 3.057333

      $Petal.Length
      [1] 3.758

      $Petal.Width
      [1] 1.199333
  3. With the iris dataset still loaded,
    1. write R code(s) to return a vector of 4 items that correspondto the averages of the first 4 columns iniris. The contents of the vector shouldbe as follows:

Sepal.Length

Sepal.Width

Petal.Length

Petal.Width

5.843333

3.057333

3.7580000

1.199333

  1. The following R code converts the contents of the first 4columns in iris to a matrix calleddata.
    data=as.matrix(iris[,1:4])
    1. Write R code(s) to use apply() to return a vector that containsthe max values of the 4 columns. The contents of the vector shouldbe as follows [Hint, use max()]:

Sepal.Length

Sepal.Width

Petal.Length

Petal.Width

7.9

4.4

6.9

2.5

  1. Write R code(s) to read the contents of the provided fileCOS-206-ShoppingCart.html into a variable calledcart and then show the first 5 lines ofcart.

Answer & Explanation Solved by verified expert
3.5 Ratings (409 Votes)
    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students