R programming



Comments



Description

R prog… QUIZ 1 r programming Question 1 The R language is a dialect of which of the following programming languages? Your Answer S Correct Score Explanation 1.00 R is a dialect of the S language which was developed at Bell Labs. C Java Scheme Total 1. Which of the following is NOT one of the freedoms that are part of the definition? .00 Question 2 The definition of free software consists of four freedoms (freedoms 0 through 3).00 / 1. The freedom to redistribute copies so you can help your neighbor.00 This is not part of the free software definition. The freedom to run the program. . The freedom to prevent users from Corre ct using the software for undesirable purposes. for any purpose. The freedom to study how the program works. and adapt it to your needs. Freedom 0 requires that the users of free software be free to use the software for any purpose.Your Answer Score Explanation 1. 00 / 1.Total 1.00 'list' is not an atomic data type in R.00 Question 3 In R the following are all atomic data types EXCEPT Your Answer list numeric integer Correct Score Explanation 1. . 4L in R.00 / 1.complex Total 1.00 Question 4 If I execute the expression x <. what is the class of the object `x' as determined by the `class()' function? Your Answer complex matrix Score Explanation . "a".00 / 1.00 Question 5 What is the class of the object defined by the expression x <. TRUE)? Your Answer logical Score Explanation .c(4.00 The 'L' suffix creates an integer vector as opposed to a numeric vector.logical integer Correct Total 1. 1. Question 6 If I have two vectors x <.00 Question Explanation R does automatic coercion of vectors so that all elements of the vector are the same data class.integer mixed charact Corre ct 1. er Total 1. y)? .c(1. what is produced by the expression cbind(x. 2.00 The character class is the "lowest common denominator" here and so all elements will be coerced into that class.00 / 1.c(3. 5) and y <. 10).3. It then takes those vectors and binds them together column-wise to create a matrix. ct columns and 3 rows a vector of length 2 a 2 by 2 matrix a 3 by 3 matrix Total 1.00 The 'cbind' function treats vectors as if they were columns of a matrix.00 .00 / 1.Your Answer a matrix with 2 Corre Score Explanation 1. 00 Explanation .Question 7 A key property of vectors in R is that Your Answer Score elements of a vector can be of different classes the length of a vector must be less than 32.768 elements of a vector all must be of the same class elements of a vector can only be character or numeric Correct 1. "b". TRUE). a list containing the letter "a".00 Question 8 Suppose I have a list defined as x <.00 / 1.list(2.Total 1. a character vector containing the element "2". Score Explanation . "a". What does x[[1]] give me? Your Answer a list containing the number 2. 2.a numeric vector of length 1. a numeric vector with elements 3.00 Question 9 Suppose I have a vector x <. Correct Total 1.00 / 1. What is produced by the expression x + y? Your Answer Score a numeric vector with elements 3. 5. 4. 6.00 1. Correct 1.2. 3.1:4 and a vector y <. 6.00 Explanation . 00 / 1. Total 1. 3. 4.an integer vector with elements 3. 2. 10) and I want to set all elements of this vector that are greater than 10 to be equal to 4.4 Corre ct Score Explanation 1.c(17.00 Question 10 Suppose I have a vector x <. an integer vector with elements 3. 4. 2. 6. 13. What R code achieves this? Your Answer x[x > 10] <. 5. 12. . 14.00 You can create a logical vector with the expression x > 10 and then use the [ operator to subset the original vector x. 3. what are the column names of the dataset? .x[x > 10] == 4 x[x == 4] > 10 x[x == 10] <.00 / 1.00 Question 11 In the dataset provided for this Quiz.4 Total 1. Correc t Day Total 1.00 You can get the column names of a data frame with the `names()' function. Wind Ozone.R.R. Solar. 6 Month. Wind 1.00 / 1. 4. Ozone. Temp. Solar.Your Answer Score Explanation 1. 5.00 . Wind. Month. 2. 3. Temp. Day. R Wind Temp Month Day 1 41 190 7.3 82 5 11 7 17 Corre ct Ozone Solar.9 74 274 10.4 67 5 1 2 36 118 8.0 72 5 2 Ozone Solar.00 You can extract the first two rows using the [ operator and an integer sequence to index the rows.Question 12 Extract the first 2 rows of the data frame and print them to the console.R Wind Temp Month Day . What does the output look like? Your Answer Score Explanation 1.R Wind Temp Month Day 1 7 2 35 NA 6. Ozone Solar. rows) are in this data frame? Your Answer 45 Score Explanation .7 81 7 22 Total 1.8 67 9 17 2 NA 258 9.1 9 24 10.9 71 2 18 131 8.00 Question 13 How many observations (i.R Wind Temp Month Day 1 18 224 13.e.0 76 9 14 9 29 Ozone Solar.00 / 1. 00 Question 14 Extract the last 2 rows of the data frame and print them to the console.00 / 1. What does the output look like? Your Answer Score Explanation . 129 Total 1.00 You can use the `nrows()' function to compute the number of rows in a data frame.160 153 Correct 1. R Wind Temp Month Day 152 18 131 8.7 82 8 19 6 7 Correc t Ozone Solar.7 62 223 8.R Wind Temp Month Day 152 11 153 108 44 9.00 The `tail()' function is an easy way to extract the last few elements of an R object.9 78 153 29 127 9.0 85 5 20 7 25 Ozone Solar.Ozone Solar.3 76 5 17 9 18 Ozone Solar. .0 76 9 29 1.R Wind Temp Month Day 152 31 244 10.R Wind Temp Month Day 152 34 307 12.0 66 153 13 27 10. 00 / 1.00 The single bracket [ operator can be used to extract individual rows of a data frame.153 20 223 11. 34 21 63 Correct .00 Question 15 What is the value of Ozone in the 47th row? Your Answer Score Explanation 1.5 68 9 30 Total 1. 00 Question 16 How many missing values are in the Ozone column of this data frame? Your Answer 9 43 Score Explanation .18 Total 1.00 / 1. na' function can be used to test for missing values.00 Question Explanation The `is. Question 17 What is the mean of the Ozone column in this dataset? Exclude missing values (coded as NA) from this calculation. Your Answer 31.00 / 1.00 1.5 Score Explanation .78 37 Correct Total 1. 0 42.00 Question Explanation The `mean' function can be used to calculate the mean.2 18.R in this subset? .1 Correct Total 1. Question 18 Extract the subset of rows of the data frame where Ozone values are above 31 and Temp values are above 90. What is the mean of Solar.00 / 1.00 1.53. .0 212.00 Question Explanation You need to construct a logical vector in R to match the question's requirements.00 185.0 334. Then use that logical vector to subset the data frame.00 / 1.Your Answer Score Explanation 205.8 Correct 1.9 Total 1. 2 79.1 Correct 1.6 90.00 Explanation .Question 19 What is the mean of "Temp" when "Month" is equal to 6? Your Answer Score 75.3 85. e.Total 1.00 Explanation .00 Question 20 What was the maximum ozone value in the month of May (i.00 / 1. Month = 5)? Your Answer Score 97 18 115 Correct 1. 00 QUIZ 2 r programming .00 / 1.100 Total 1. Score Explanation . A warning is given with no value returned.Question 1 Suppose I define the following function in R cube <. n) { x^3 } What is the result of running cube(3) in R after defining this function? Your Answer The users is prompted to specify the value of 'n'.function(x. 00 / 1. it is not needed even though it is a formal argument.00 An error is returned because 'n' is not specified in the call to 'cube' Total Question 2 The following code will produce a warning in R.1:10 if(x > 5) { x <. x <. .00 Because 'n' is not evaluated.0 } Why? 1.The number 27 is returned Corre ct 1. 00 Explanation . 'x' is a vector of length 10 and 'if' can only test a single logical statement. The syntax of this R expression is incorrect. Correct 1. There are no elements in 'x' that are greater than 5 You cannot set 'x' to be 0 because 'x' is a vector and 0 is a scalar.Your Answer Score The expression uses curly braces. function(y) { y+z } z <.10 f(3) What value is returned? .Total 1.function(x) { g <.00 Question 3 Consider the following function f <.4 x + g(x) } If I then run in R z <.00 / 1. 00 Explanation .Your Answer Score 4 16 7 10 Total Question 4 Correct 1.00 / 1.00 1. Consider the following expression: x <.5 y <.if(x < 3) { NA } else { 10 } What is the value of 'y' after evaluating this expression? Your Answer NA 5 Score Explanation . d = 3L) { z <.null(y)) z <.x + y / z . d) if(!is.10 Correct 1.00 Question 5 Consider the following R function h <.00 / 1.z + y else z <.z + f g <. y = NULL.00 3 Total 1.function(x.cbind(x. g + 10 g } Which symbol in the above function is a free variable? Your Answer f z d Score Correct 1.if(d == 3L) return(g) g <.00 Explanation . 00 / 1.00 Question 6 What is an environment in R? Your Answer a collection of symbol/value pairs Score Correct 1.L g Total 1.00 Explanation . 00 / 1.00 Question 7 The R language uses what type of scoping rule for resolving free variables? Your Answer Score Explanation .a special type of function an R package that only contains data a list whose elements are all functions Total 1. 00 dynamic scoping compilation scoping global scoping Total Question 8 How are free variables in R functions resolved? 1.00 .lexical scoping Correct 1.00 / 1. Your Answer Score The values of free variables are searched for in the environment in which the function was called The values of free variables are searched for in the global environment The values of free variables are searched for in the environment in which the function was Correc 1.00 Explanati on .00 t defined The values of free variables are searched for in the working directory Total 1.00 / 1. 00 Explanation .Question 9 What is one of the consequences of the scoping rules used in R? Your Answer All objects must be stored in memory All objects can be stored on the disk Functions cannot be nested R objects cannot be larger than 100 MB Score Correct 1. 00 Question 10 In R. what is the parent frame? Your Answer Score It is always the global environment It is the environment in which a function was defined It is the environment in which a function was called Correct 1.Total 1.00 / 1.00 Explanation . 00 .00 / 1.It is the package search list Total 1. QUIZ 3 r programming Question 1 Take a look at the 'iris' dataset that comes with R. what is the mean of 'Sepal. The data can be loaded with the code: library(datasets) data(iris) A description of the dataset can be found by running ?iris There will be an object called 'iris' in your workspace. In this dataset.) .Length' for the species virginica? (Please only enter the numeric result and nothing else. what R code returns a vector of the means of the variables 'Sepal.Length'. 1.00 To get the answer here.00 / 1.588 Correc t Total Score Explanation 1.Width'? .Width'.Answer for Question 1 You entered: Your Answer 6.Length'. 'Sepal. and 'Petal. you can use 'tapply' to calculate the mean of 'Sepal.00 Question 2 Continuing with the 'iris' dataset from the previous Question. 'Petal.Length' within each species. mean) apply(iris.00 / 1. 2. 1. 1:4].00 apply(iris[. 1:4]. mean) Score Correct 1. 1.Your Answer apply(iris[.00 Explanation . mean) colMeans(iris) Total Question 3 1. cyl. You can find some information about the dataset by running ?mtcars How can one calculate the average miles per gallon (mpg) by number of cylinders in the car (cyl)? Your Answer sapply(split(mtcars$mpg. mtcars$cyl).Load the 'mtcars' dataset in R with the following code library(datasets) data(mtcars) There will be an object names 'mtcars' in your workspace. mean) split(mtcars. mean) sapply(mtcars.00 Explanation . mtcars$cyl) Score Correct 1. apply(mtcars, 2, mean) Total 1.00 / 1.00 Question 4 Continuing with the 'mtcars' dataset from the previous Question, what is the absolute difference between the average horsepower of 4cylinder cars and the average horsepower of 8-cylinder cars? Answer for Question 4 You entered: Your Answer Score Explanation 126.57793 Correct Total 1.00 1.00 / 1.00 Question 5 If you run debug(ls) what happens when you next call the 'ls' function? Your Answer Execution of the 'ls' function will suspend at the 4th line of the function and you will be in the browser. The 'ls' function will execute as usual. Score Explana ion Execution of 'ls' will suspend at the beginning of the function and you will be in the browser. Corre 1.00 ct You will be prompted to specify at which line of the function you would like to suspend execution and enter the browser. Total 1.00 / 1.00 Score Explanation . 1.seed(1) rpois(5. 4. 2) Your Answer A vector with the numbers 1.QUIZ 4 r programming Question 1 What is produced at the end of this snippet of R code? set. 2. 1.5. 1. 1. 5 It is impossible to tell because the result is random A vector with the numbers 1.5. 0.1. `rpois()' will always output the same vector in this code. 1 A vector with the numbers 3.1.7 Total Question 2 1.00 / 1.seed()' function is used.00 4.3. Corre ct 1. 2.00 Because the `set. . 00 Functions beginning with the `r' prefix are used to simulate random variates.00 .What R function can be used to generate standard Normal random variables? Your Answer Score Explanation 1.00 / 1. qnorm rnorm Correct dnorm pnorm Total Question Explanation 1. evaluate the cumulative density.seed() function important? Your Answer It ensures that the sequence of random numbers starts in a specific place and is therefore reproducible. why is using the set. evaluate the density. Score Correc t 1.00 Explanat on . Question 3 When simulating data.Standard probability distributions in R have a set of four functions that can be used to simulate variates. It ensures that the sequence of random numbers is truly random. and evaluate the quantile function. It ensures that the random numbers generated are within specified boundaries. It can be used to generate non-uniform random numbers.00 Question 4 Which function can be used to evaluate the inverse cumulative distribution function for the Poisson distribution? Your Answer rpois ppois Score Explanation . Total 1.00 / 1. 00 Probability distribution functions beginning with the `q' prefix are used to evaluate the quantile (inverse cumulative distribution) function. 0. 20) y <.0.seed(10) x <.00 Question 5 What does the following code do? set. each = 5) e <. dpois Total 1.rnorm(10.00 / 1.5 + 2 * x + e Your Answer Score Explanation .qpois Corre ct 1.rep(0:1. 00 Generate data from a Poisson generalized linear model Generate uniformly distributed random data Total Question 6 What R function can be used to generate Binomial random variables? 1.00 .00 / 1.Generate random exponentially distributed data Generate data from a Normal linear model Correct 1. Your Answer Score pbinom qbinom rbinom Correct 1.00 / 1.00 Explanation .00 dbinom Total Question 7 1. 00 Explanation .00 the working directory the global environment the package search list Total 1.00 / 1.What aspect of the R runtime does the profiler keep track of when an R expression is evaluated? Your Answer the function call stack Score Correct 1. x1.) Without running the code. what percentage of the run time is spent in the 'lm' function.Question 8 Consider the following R code library(datasets) Rprof() fit <.total' method of normalization shown in 'summaryRprof()'? Your Answer 100% It is not possible to tell Score Explanation .lm(y ~ x1 + x2) Rprof(NULL) (Assume that y. based on the 'by. and x2 are present in the workspace. 00 50% Total 0.00 Question 9 When using 'system.time()'.23% Inorrect 0. what is the user time? Your Answer It is the time spent by the CPU waiting for other tasks to finish Score Explanation .00 / 1. It is the time spent by the CPU evaluating an expression It is a measure of network latency It is the "wall-clock" time it takes to evaluate an expression Total 0.00 Question 10 If a computer has more than one available processor and R is able to take advantage of that. then which of the following is true when using 'system.time()'? Your Answer Score Explanation .00 / 1. 00 1.00 .00 / 1.elapsed time is 0 user time is always smaller than elapsed time user time is 0 elapsed time may be smaller than user time Total Correct 1.
Copyright © 2024 DOKUMEN.SITE Inc.