SOME SOLUTION
5.
## read data as matrix lunch=matrix(c(2829,433,394,431,401, 9201,1092,733,691,1256, 14764,877,531,337,1652,
14759,1119,71,42,319), byrow=T, ncol=5)
colnames(lunch)=c("home","canteen","rest","bar","work_pl") rownames(lunch)=c("Bachelor","A-level","GCSE","Primary") lunch
## margins -- sum of each row and column -- total margin.table(lunch,1);margin.table(lunch,2);sum(lunch)
## percent of the total
p_lunch=prop.table(lunch); round(p_lunch*100,1) barplot(p_lunch,beside=F)
## row profiles (percentage)
r_lunch=prop.table(lunch,1); round(r_lunch*100,1) par(mfrow=c(1,dim(r_lunch)[1]))
for (i in 1:dim(r_lunch)[1])
{ barplot(r_lunch[i,],ylim=c(0,1),main=rownames(lunch)[i]) abline(h=0) }
par(mfrow=c(1,1))
par(mfrow=c(1,dim(c_lunch)[2])) for (j in 1:dim(c_lunch)[2])
{ barplot(c_lunch[,j],ylim=c(0,0.5),main=colnames(lunch)[j]) abline(h=0) }
par(mfrow=c(1,1)