Below are the solutions to these.
#################### # # # Exercise 1 # # # #################### #What is the output of: ifelse(sqrt(9)<2,sqrt(9),0)
## [1] 0
#################### # # # Exercise 2 # # # #################### #What is the output of: ifelse(sqrt(100)>9,sqrt(100),0)
## [1] 10
#################### # # # Exercise 3 # # # #################### #What is the uotput y of: x=12 if(is.numeric(x)) y=x*2 y
## [1] 24
#################### # # # Exercise 4 # # # #################### #What is the uotput x,y of: z=-1 if(z<0){x=abs(z);y=z*3} x
## [1] 1
y
## [1] -3
#################### # # # Exercise 5 # # # #################### #What is the uotput y of: z=6 if(z<0) y=z*3 else y=z*5 y
## [1] 30
#################### # # # Exercise 6 # # # #################### #What is the uotput z of: x=15 y=3 if(is.numeric(x)) if(is.numeric(y) & y!=0) z=x/y z
## [1] 5
#################### # # # Exercise 7 # # # #################### #What is the output of: if (is.numeric(x)) print('is numeric') else if(is.character(x)) print('is character')
## [1] "is numeric"
#################### # # # Exercise 8 # # # #################### #What is the output of: x=90 ifelse(x<100,ifelse(x/2==trunc(x/2),x/2,0),ifelse(x/100==trunc(x/100),x/100,-1))
## [1] 45
x=120 ifelse(x<100,ifelse(x/2==trunc(x/2),x/2,0),ifelse(x/100==trunc(x/100),x/100,-1))
## [1] -1
x=200 ifelse(x<100,ifelse(x/2==trunc(x/2),x/2,0),ifelse(x/100==trunc(x/100),x/100,-1))
## [1] 2
#################### # # # Exercise 9 # # # #################### #What is the output n of: z='i' if (z %in% letters) if (z=='a') n=1 else if (z=='e') n=2 else if (z=='i') n=3 else if (z=='o') n=4 else n=5 n
## [1] 3
#################### # # # Exercise 10 # # # #################### #What is the output n of: z='u' if (z %in% letters) if (z=='a') n=1 else if (z=='e') n=2 else if (z=='i') n=3 else if (z=='o') n=4 else n=5 n
## [1] 5
Leave a Reply