Please help me to solve this question in R. I need all steps and R-code. Thank y
ID: 3441048 • Letter: P
Question
Please help me to solve this question in R. I need all steps and R-code. Thank youPlease help me to solve this question in R. I need all steps and R-code. Thank you
Run the following line to obtain a bivariate table for hair and eye color in a sample of 279 men. Make a stacked relative frequency barplot with hair color on the z-axis. Add a legend. Use the Make a stacked relative frequency barplot with hair color on the z axis. Add a legend. Use the category colors "saddlebrown" for brown eyes, "lightblue" for blue eyes, "violet" for hazel eyes, and "palegreen" for green eyes male. HairEyeColor HairEyeColor I, ,11 Among blonds, what eye color is most prevalent in the sample?
Explanation / Answer
You did not provide the data so i cannot give you the output. But the generic R-code is as follows
Let f_i denote the frequency of ith class and N be the total frequency. Then relative frequency in R can be computed as follows, say we have k classes
rel.freq=rep(0,k)
hair colour=c("brown","blue","violet","palegreen")
for(i in 1:k)
{
rel.freq[i]=f[i]/N
}
barplot(rel.freq,x=hair color, colours=c("saddlebrown","lightblue","violet","palegreen")
legend(hair color,rel.freq,legend="")