In: Statistics and Probability
> convert(8.3,"inches")
[1] 0.21082
> convert(8.3,"feet")
[1] 2.52984
> convert(8.3,"foot")
Error in convert(8.3, "foot") : the unit was not "inches" or "feet"
Use your function to convert the values of Girth and Height to meters. Using cor.test() function, calculate the correlation (and the corresponding p-value) between Girth and Height in meters.
The R code is
convert=function(x,unit){
if(unit=="inches") x*0.0254 else if(unit=="feet") x*0.3048
else stop('the unit was not in "inches" or "feet"')
}
convert(8.3,"inches")
convert(8.3,"feet")
convert(8.3,"foot")
d=trees
attach(d)
Girth=convert(Girth,"inches")
Height=convert(Height,"feet")
cor.test(Girth,Height)
The Output is
#Here Value of Correlation coefficient is 0.5192801
#From P-Value =0.002758<=0.05 There is enough evidence to claim the population correlation coefficient is not zero.The Regression coefficient is significant