Coder Social home page Coder Social logo

rstatistics_assignmentone's Introduction

RStatistics_AssignmentOne

CAP 3330. Fall 2021

Assignment 1

Instructions

  • Create a notebook in R and write all the code and comments needed to answer the questions below.

  • The submission for this assignment consists of uploading to Blackboard the results of running all the code in the notebook that you will create. You can submit either a PDF with all the results OR an HTML document with all the results.

  • Make sure the document that you submit (the PDF or the HTML) includes:

a) The R code you used for each exercise part.

b)The R output you got after running each line of code.

c) The comments required to answer the question. For example, 9a) needs an explanation. Make sure you include that explanation too.

Questions

Tip: The code you write to answer each question must be generalizable, which means that it must work for any other dataset, not only for this dataset. For example, using as a reference question 5, the following code would not be generalizable since it only works for this dataset:

DFAsg1 [4:9, 2]

This line code is not generalizable because it takes into consideration the particular situation in this dataset, where rows from 1 to 3 belong to “A”, whereas the remaining rows belong to “B” or “C”.

  1. Write code that allows you to create a vector x with the numbers {10,20,30,100,150,10,30,50}. Then, insert the number 168 between the third and fourth elements and assign the result of this insertion to x again.

  2. Create a data frame with the following four columns: x (from the previous question), x1, x2, and y. Name the data frame DFAsg1

  • x1 and x2 are the result of generating 9 random numbers from a normal distribution with a mean of 5 and standard deviation of 1. The numbers in x1 and x2 must be rounded to 1 decimal place. Use the following code to create x1 and x2:

x1<-rnorm(9,5,1) x1<-round(x1,1)

x2<-rnorm(9,5,1) x2<-round(x2,1)

  • y is a character vector with three A’s, followed by three B’s, and then followed by three C’s (you need to create the vector y by yourself)
  1. Use the data frame DFAsg1 as a reference. Write ONE LINE of code that returns the standard deviation of the values of x for each of the letters A, B, and C.

  2. Use the data frame DFAsg1 as a reference. Write ONE LINE of code that returns the average of x1 and x2.

  3. Use the data frame DFAsg1 as a reference. Write ONE LINE of code that returns the values of x2 for records (rows) where the letter is B or C (i.e., return the values of x2 excluding rows where the letter is A)

  4. Add a new column to the data frame DFAsg1 with a logical vector indicating whether the value of x1 is greater than the value of x2. Name this new column “Is_x1_greater”.

  5. Display the duplicate elements in x (i.e., the values that repeat). The function duplicated () may be helpful.

Note: Notice that you must return the value or values that are duplicated.

  1. Write ONE LINE of code that returns the count of how many elements in x are greater than 50.

  2. Create a vector called “a” containing the numbers from 1 to 9. Create another vector called “b” containing the numbers from 1 to 4.

9a) Create a new vector called “sumAB” using the following expression: sumAB<- a + b. Explain how R obtains the last and second to last elements of the vector sumAB.

9b) Write ONE LINE of code that returns the total (i.e., the sum) of all the elements in vectors a and b combined.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.