Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Stats 20 Midterm 1 Practice Questions

Spring 2021

1:  my_mean

The sample mean for a sample of values x = x1 , x2 , . . . , xn  is dened as

n

i=1

Write a function called my maanu( that computes the mean of a numeric vector x of data values without using the maanu( function. Include an optional logical na -rm argument with a default value of FALsE that specifies whether to remove NA values from the computation.

2: Incorrect my_sign

Observe the following function:

my  shfn  o,  functionux(  (

if  ux    .(  (

_poshthva _

)

if  ux  o  .(  (

_nafathva _

)

if  ux  ==  .(  (

_zaro_

)

)

(a)

What is the intended purpose of my  shfnu(? For what inputs x will there be no output of my  shfnu(?

(b)

Keeping the overall he statement structure (no additional if/else statements), edit my  shfnu( so that it works as intended.

(c)

Give example inputs that would cause my  shfnu( to throw:

●    an error

 one or more warnings

(d)

Using the xed my  shfnu( function from (b), with a single command (e.g. one line of code), produce the output cu _poshthva _ )  _nafathva _ )  _zaro_(

3:  my_cumfun

Write a function called my  cumeunu( that computes the cumulative eun of a numeric vector x.  The out- put of my  cumeunux)  sum()  my  cumeunux)  prod()  my  cumeunux)  max()  my  cumeunux)  mhn( should be identical to the output of cumsumux()  cumprodux()  cummaxux()  cummhnux( respectively.

4:  is.mode

hs -lofhcalu( returns TRuE if the storage mode of the input x is logical and FALsE otherwise. hs -numarhcu( and hs -cgaractaru( work similarly. Write a function called hs -modau( which takes as inputs x: an object, and moda:  a length 1 character vector.  The output of hs -modaux)  moda( should be TRuE only if x has storage mode equal to the moda argument.

 

NОte : each part would be considered onequestion on the exam. So question 2 is really four questions.