In: Statistics and Probability
Perform the following tasks on R Studio
Construct a function called conv1 which inputs a measurement in
centimeters and outputs the corresponding measurement in inches and
construct another function called conv2 which inputs a measurement
in centimeters and outputs the corresponding measurements in
inches, feet, and meters
R code below
conv1=function(cm){
return(cm*0.393701) #since 1 cm = 0.393701inches
}
conv1(30)
conv1(25)
#above answers for inches for 30 cm and 25 cm respectively now you can use this function for any calculation from cm to inch
conv2=function(cm){
ans=rep(0,3)
ans[0]=cm*0.393701
ans[1]=cm*0.0328084
ans[2]=cm/100
return(ans)} #first ans is for cm to inches,2nd from cm to feet and
3rd from cm to mtr
conv1(30)
conv1(25)
Hope the above answer has helped you in understanding the problem. Please upvote the ans if it has really helped you. Good Luck!!