This assignment serves as practice for the material we have covered in class and
ID: 3666020 • Letter: T
Question
This assignment serves as practice for the material we have covered in class and in your assigned readings regarding chapters 1 and 2 of the text. Below are several questions to answer by typing the correct syntax directly into the R console (as we have been doing in class). When you have finished, access the File" pull-down menu and select "Save to File..." to save the entire R console as a text file called "Assignment 1.R" preceded with your first initial and last SHAYS Assignment 1.txt". Upload this to Blackboard by 2:00 pm name: Monday 2/08/2016. No other submission method will be accepted, nor will any late assignments. If you perform the assignment in multiple R sessions, save the console window each time and merge these files as necessary so that only a single text file is submitted. I will run your code and you will be graded on whether the code runs without error, whether the answers are correct, and if proper commenting of your code (use of exists in your file You will find there are numerous different syntax sequences to write code that all arrive at the exact, correct, and same answer as some other method. This is OK, any correct answer receives full credit: whether it took 20 lines to do so or a single function. These distinctions will become talking points for our lectures For the remainder ofthe assignment, comment your code when necessary using the convention. At the very least, use the comment syntax to indicate which part of which problem is being answered in order to receive full credit 5) Create the following vectors in R. a (100,95,90,..., 15,10,5) b (1,1 +O, 1 +20, 1 +30, 1+40, 1 +17 1+180, 1 +19 (a) Create a vector with the 5th 11th and 7th element of a (in that order) (b) What are the dimensions of a and b? (c) What are all of the elements of b which are between 26 and 40 inclusive? d) Sort a by the values in bExplanation / Answer
#creating vector a
a<-seq(100,5,-5)
#creating vector b
b<-seq(1,191,10)
#creating a vector c with 5th , 11th, 7th elements of a
c<-a[c(5,11,7)]
#dimention od a and b
cat("dimentions of vector a = ")
str(length(a))
cat("dimentions of vector b = ")
str(length(b))
#selecting elemnts of b which are between 26 and 40
d<-b[b>=26 & b<=40]