Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getwd()
- setwd("C:\\Users\\cr\\Desktop\\cr")
- getwd()
- data2<-read.csv("lab3.csv",header = TRUE)
- fix(data2)
- names(data2)<-c("Age","Gender","Accomadation")
- #giving related values to the data in the csv using vectors
- data2$Gender<-factor(data2$Gender,c(1,2),c("male","female"))
- data2$Accomadation<-factor(data2$Accomadation,c(1,2,3),c("Home","Boarded","Lodging"))
- #Remeber to attch the file othewise every thing will be a mess soon.
- attach(data2)
- #sorting data acording to the Frequency
- GenderFreq<-table(Gender)
- fix(data2)
- print(GenderFreq)
- AccoFreq<-table(Accomadation)
- print(AccoFreq)
- #creating charts
- pie(GenderFreq, main="pie chart for Gender")
- #Naming bars of the bar charts
- barplot(GenderFreq, main="bar chart for gender",xlab = "Type",names.arg = c("Men","Girls"))
- #addig colors o the bar charts
- barplot(GenderFreq, main="bar chart for gender",xlab = "Type",names.arg = c("Men","Girls"),col = "blue")
- # axis will drawn at the 0 point
- barplot(GenderFreq, main="bar chart for gender",xlab = "Type",names.arg = c("Men","Girls"))
- abline(h=10)
- #describe two things together(using two clomns at once)
- gender_accomedation_freq<-table(Gender,Accomadation)
- print(gender_accomedation_freq)
- barplot(gender_accomedation_freq,main = "Comparing both")
- #showing legends
- barplot(gender_accomedation_freq,main = "Comparing both",legend=rownames(gender_accomedation_freq))
- #side by side
- barplot(gender_accomedation_freq,main = "Comparing both",legend=rownames(gender_accomedation_freq),beside = TRUE)
- #Generating boxplot
- boxplot(Age~Gender,main="boxplot for age by gender", xlab="Gender",ylab="Age")
- #outpitch(8 means star , try differen numbers see the results)
- boxplot(Age~Accomadation,outpch=8,main="boxplot for age by gender", xlab="Gender",ylab="Age")
- #finding mean value
- xtabs(Age~Gender+Accomadation)/gender_accomedation_freq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement