SHARE
TWEET

03

crhunter Sep 19th, 2019 (edited) 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. getwd()
  2. setwd("C:\\Users\\cr\\Desktop\\cr")
  3. getwd()
  4. data2<-read.csv("lab3.csv",header = TRUE)
  5. fix(data2)
  6. names(data2)<-c("Age","Gender","Accomadation")
  7. #giving related values to the data in the csv using vectors
  8. data2$Gender<-factor(data2$Gender,c(1,2),c("male","female"))
  9. data2$Accomadation<-factor(data2$Accomadation,c(1,2,3),c("Home","Boarded","Lodging"))
  10. #Remeber to attch the file othewise every thing will be a mess soon.
  11. attach(data2)
  12.  
  13. #sorting data acording to the Frequency
  14. GenderFreq<-table(Gender)
  15. fix(data2)
  16.  
  17. print(GenderFreq)
  18.  
  19. AccoFreq<-table(Accomadation)
  20. print(AccoFreq)
  21.  
  22. #creating charts
  23. pie(GenderFreq, main="pie chart for Gender")
  24. #Naming bars of the bar charts
  25. barplot(GenderFreq, main="bar chart for gender",xlab = "Type",names.arg = c("Men","Girls"))
  26. #addig colors o the bar charts
  27. barplot(GenderFreq, main="bar chart for gender",xlab = "Type",names.arg = c("Men","Girls"),col = "blue")
  28. # axis will drawn at the 0 point
  29. barplot(GenderFreq, main="bar chart for gender",xlab = "Type",names.arg = c("Men","Girls"))
  30. abline(h=10)
  31. #describe two things together(using two clomns at once)
  32. gender_accomedation_freq<-table(Gender,Accomadation)
  33. print(gender_accomedation_freq)
  34.  
  35. barplot(gender_accomedation_freq,main = "Comparing both")
  36. #showing legends
  37. barplot(gender_accomedation_freq,main = "Comparing both",legend=rownames(gender_accomedation_freq))
  38. #side by side
  39. barplot(gender_accomedation_freq,main = "Comparing both",legend=rownames(gender_accomedation_freq),beside = TRUE)
  40. #Generating boxplot
  41. boxplot(Age~Gender,main="boxplot for age by gender", xlab="Gender",ylab="Age")
  42. #outpitch(8 means star , try differen numbers see the results)
  43. boxplot(Age~Accomadation,outpch=8,main="boxplot for age by gender", xlab="Gender",ylab="Age")
  44. #finding mean value
  45. xtabs(Age~Gender+Accomadation)/gender_accomedation_freq
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top