R程序设计题目求助,同学们可以练练手,看看名校的题目是不是很难? 做出的同学可以回贴以附件形式出售,50个币以内购买。
(b) (i) Write code to create three vectors Time, Status and Funded with values as in the table below. Time should be numeric, Status should be a factor with the levels which occur in the table, and Funded should be a logical vector. |
Time Status Funded |
1.5 Planned TRUE |
2.3 Commenced FALSE |
5.8 Commenced TRUE |
3.4 Completed TRUE |
(ii) Write code to create a data frame named Prajects containing these vectors as named columns. |
(iii) Write code which uses sapply to find out which columns of Praj ects are numeric. |
(iv) What would be the format of the output of the call to sapply? |
(v) Write code to create a table of the values in the second column of the data frame. |
|
(c) Write a function named UnifarmMean which has a single argument sampleSize with default value 100. The function should obtain a sample of size sampleSize from the uniform distribu tion on the unit interval using the function runif and return the mean of the sample.
|
(d) Write a function named Unifarmlnterval which has arguments intervalSize, with de fault value 0.05, and maxIter, the maximum number of iterations to perform, with default value 1000. The function should repeatedly call UnifarmMean with a sampleSize of 1, until either the mean of all the samples obtained is within intervalSize of 0.5 or maxlter iter ations have been completed. If it stops before the maximum number of iterations has been completed, it should display, with appropriate text, the number of times UnifarmMean has been called, and return this number. If it stops because the maximum number of iterations has been completed, it should display a message to this effect and returnmaxlter. |