Professional Documents
Culture Documents
Feedback - Week 2 Quiz
Feedback - Week 2 Quiz
FeedbackWeek2Quiz HelpCenter
YousubmittedthisquizonSun14Jun201510:56PMAEST.Yougotascore
of10.00outof10.00.
Question1
SupposeIdefinethefollowingfunctioninR
cube<function(x,n){
x^3
}
Whatistheresultofrunning
cube(3)
inRafterdefiningthisfunction?
Awarningisgivenwithnovalue
returned.
Anerrorisreturnedbecause'n'is
notspecifiedinthecallto'cube'
Theusersispromptedtospecify
thevalueof'n'.
Total 1.00/
1.00
Question2
ThefollowingcodewillproduceawarninginR.
x<1:10
https://class.coursera.org/rprog015/quiz/feedback?submission_id=25669 1/6
6/14/2015 Coursera
if(x>5){
x<0
}
Why?
'x'isavectoroflength10and'if'canonlytestasingle 1.00
logicalstatement.
Youcannotset'x'tobe0because'x'isavectorand0isa
scalar.
Therearenoelementsin'x'thataregreaterthan5
Theexpressionusescurlybraces.
ThesyntaxofthisRexpressionisincorrect.
Total 1.00/
1.00
Question3
Considerthefollowingfunction
f<function(x){
g<function(y){
y+z
}
z<4
x+g(x)
}
IfIthenruninR
z<10
f(3)
Whatvalueisreturned?
16
https://class.coursera.org/rprog015/quiz/feedback?submission_id=25669 2/6
6/14/2015 Coursera
10 1.00
Total 1.00/1.00
Question4
Considerthefollowingexpression:
x<5
y<if(x<3){
NA
}else{
10
}
Whatisthevalueof'y'afterevaluatingthisexpression?
10 1.00
NA
Total 1.00/1.00
Question5
ConsiderthefollowingRfunction
h<function(x,y=NULL,d=3L){
z<cbind(x,d)
if(!is.null(y))
z<z+y
else
z<z+f
g<x+y/z
if(d==3L)
return(g)
https://class.coursera.org/rprog015/quiz/feedback?submission_id=25669 3/6
6/14/2015 Coursera
g<g+10
g
}
Whichsymbolintheabovefunctionisafreevariable?
f 1.00
Total 1.00/1.00
Question6
WhatisanenvironmentinR?
aspecialtypeoffunction
acollectionofsymbol/valuepairs 1.00
alistwhoseelementsareallfunctions
anRpackagethatonlycontainsdata
Total 1.00/1.00
Question7
TheRlanguageuseswhattypeofscopingruleforresolvingfreevariables?
dynamicscoping
https://class.coursera.org/rprog015/quiz/feedback?submission_id=25669 4/6
6/14/2015 Coursera
compilationscoping
lexicalscoping 1.00
globalscoping
Total 1.00/1.00
Question8
HowarefreevariablesinRfunctionsresolved?
Thevaluesoffreevariablesaresearchedforinthe
environmentinwhichthefunctionwascalled
Thevaluesoffreevariablesaresearchedforinthe 1.00
environmentinwhichthefunctionwasdefined
Thevaluesoffreevariablesaresearchedforintheglobal
environment
Thevaluesoffreevariablesaresearchedforintheworking
directory
Total 1.00/
1.00
Question9
WhatisoneoftheconsequencesofthescopingrulesusedinR?
Allobjectsmustbestoredinmemory 1.00
Robjectscannotbelargerthan100MB
Functionscannotbenested
Allobjectscanbestoredonthedisk
Total 1.00/1.00
https://class.coursera.org/rprog015/quiz/feedback?submission_id=25669 5/6
6/14/2015 Coursera
Question10
InR,whatistheparentframe?
Itistheenvironmentinwhichafunctionwasdefined
Itisthepackagesearchlist
Itistheenvironmentinwhichafunctionwascalled 1.00
Itisalwaystheglobalenvironment
Total 1.00/1.00
https://class.coursera.org/rprog015/quiz/feedback?submission_id=25669 6/6