# Title: Control Structure in R # Student name 1: # Student name 2: # Comments (e.g, known bugs, questions you would like Dr. Cao to go through in the class, etc): #1. Download "DATA133_example1.csv" from course website, and use read.table function to read all contents to variable "data". Please set sep parameter and header parameter: data <- read.table(path, sep=",", header=T) #2. Use head function to check the first few elements of the data, and check the names attribute of "data". #3. Use two different ways to print the last column of "data" (Column name is iwght, it is 7th column) #4. Use For loop to check each row, and print that row if the iwght value in that row is larger than 0.002, but stop printing the rest if the value is less than 0.001. Hint: nrow function could be used, your program should print: 0.0047974104, 0.0026203753, 0.0026384928 #5. Check each pair of two rows, print out these two rows if the sum of permno column for them is less than 40000. Hint: use nested loop, and there would be two condition in the if statement: row number i and j are different, the sum of permno is less than 40000. #6. Read each row of "data", print the first row whose adj_prc column is less than 20. Hint: Use a loop and also break. You should print the #4 row. #7. Read each row of "data", print the last row whose adj_prc column is less than 20. Hint: You should print the #4798 row. #8. Calculate the sum of all adj_prc column, but if any value less than 20, please ignore them. Hint: You should use a loop and also next. #9. Check each data record's TICKER name, print "Long" if the length is large than 3, print "Medium" if the length is 3, print "Short" if the length is less than 3. #10. When looking at a dataset, we may want to sort the data in an order that makes more sense for analysis. For example, we could use sort(x) to sort all values in x variable. In addition, the function order() returns the index vector needed to sort the vector. This implies that sort(x) and x[order(x)] give the same result. This can be useful for finding row numbers with certain properties such as "the row for the record with the smallest adj_prc". #(1). Access adj_prc from the data and store it in pop. #(2). Use sort function to sort pop #(3). Use the function order, to order pop and store in object o #(4). Find the index number of the entry data record with the smallest adj_prc