Guideline to report for this lab:
1) You need to type your lab report, and only a SINGLE PDF document is accepted.
2) Answer TWO questions out of 1, 2 , 3 and 4 (each 50 points). Q5 is optional (no bonus points will be given). Due on Nov 3, 2022 in class..
3) For each question, please do the following
a) Please include a clear description of your algorithm (or procedure) (10 points).
b) Please Include your R code (20 points=15 points for correctness + 5 points for readability).
c) Please include three non-trivial test cases and their output by your R code (15 points).
d) Clarity of the writing (5 points).
1. Find the position index of the second smallest value in a given list
Give a list of values, find the second smallest value in this list. Also report its position index. For example, given a list 1, 2.5, 0.8, 19.5, 13, -29, 43, you would answer 3.
Hint: an example R code can be found here.
2. Print all prime numbers less than a given number
Give a positive integer N, count the number of prime numbers less than N and then print all these prime numbers. For example, given N=10, you would answer 4 and print 2, 3, 5, 7.
Hint: an example R code can be found here.
3. Largest interval
Given a list of numbers, write a function that return the largest interval, along with the size of the interval. For example, if the list consists of 3,1,5,20,18,11,1,7,6, then you will return interval [11,18] and interval size 7. One example of returned value is a data frame named as interval, such that interval$intL=11, interval$intR=18, interval$Size=7.
Hint: an example R code can be found here. Note that this code does not handle ties.
4. Frequency counts
Given a list of numbers, and the number of intervals, write a function that return the count of numbers in each equal-sized interval. For example, if you are given a list consisting of the following numbers
3,1,5,20,18,11,1,7,6,33,28.1,21.9,15,11,9,25,29,30.5,10,14,15.1,17.5,22.4,25.9, 4.5, 2.1,35,0
and the number of intervals is 5, then you will return a list consisting of the counts in each of the following intervals
[0,7), [7,14), [14,21), [21,28), [28,35],
which are 8, 5, 6, 4, 5, respectively. Note that here we adopt the convention that the last interval is closed on both sides. To program this, you first compute the size of the spread which is 35-0=35. As the number of intervals is 5, the size of each interval is 7. So the intervals are listed as above. Then you count the number of values falling in each of the intervals.
Hint: an example R code can be found here.
5. Transaction records (optional)
Download the attached transaction records file, "trans.Rdata", find the largest (in terms of transaction amount) 10000 transactions after April 1, 2016. The first column is time stamp of the transaction, and second the amount of transaction.
1) Describe your algorithm and indicate its computational complexity. R functions such as sort(), order(), or rank() can be used, but are not recommended. Here is an example on R code for selecting top K entries from a list, and the code to extract all transactions after April 1, 2016 is as follows
> tmp<-read.table("trans.Rdata",sep=",",header=T);
> x<-tmp[as.character(tmp[,1])>"20160401:000000",];
2) Compare the computation time of your algorithm and the sort() function in R.
3) Please attach your R code.