Sameer Mathur
AllCities.df <- read.csv(paste("AllCitiesData.csv", sep=""))
attach(AllCities.df)
dim(AllCities.df)
[1] 6467 18
# Method 1: using aggregate()
aggregate(RoomRent, by=list(TouristDestination = IsTouristDestination), mean)
TouristDestination x
1 No 4507.500
2 Yes 6790.124
# Method 2: using by()
by(RoomRent, IsTouristDestination, mean)
IsTouristDestination: No
[1] 4507.5
--------------------------------------------------------
IsTouristDestination: Yes
[1] 6790.124
aggregate(RoomRent, by=list(TouristDestination = IsTouristDestination, FreeBreakfast = FreeBreakfast), mean)
TouristDestination FreeBreakfast x
1 No No 4672.975
2 Yes No 6355.771
3 No Yes 4424.362
4 Yes Yes 7096.756
aggregate(RoomRent, by=list(TouristDestination = IsTouristDestination, FreeWifi = FreeWifi), mean)
TouristDestination FreeWifi x
1 No No 4151.906
2 Yes No 5894.469
3 No Yes 4529.812
4 Yes Yes 6885.568
aggregate(RoomRent, by=list(TouristDestination = IsTouristDestination, SwimmingPool = HasSwimmingPool), mean)
TouristDestination SwimmingPool x
1 No No 3328.812
2 Yes No 3966.258
3 No Yes 6691.175
4 Yes Yes 10563.975
library(gplots)
plotmeans(RoomRent ~ IsTouristDestination, data = AllCities.df, frame = FALSE)
library(gplots)
plotmeans(RoomRent ~ FreeBreakfast, data = AllCities.df, frame = FALSE)
library(gplots)
plotmeans(RoomRent ~ FreeWifi, data = AllCities.df, frame = FALSE)
library(gplots)
plotmeans(RoomRent ~ HasSwimmingPool, data = AllCities.df, frame = FALSE)
boxplot(RoomRent ~ IsTouristDestination, data=AllCities.df, horizontal=TRUE,
ylab="Tourist Destination", xlab="Room Rent (INR)", las=1,
main="Comparison of Room Rent corresponding to Tourist Destination")
boxplot(RoomRent ~ FreeWifi, data=AllCities.df, horizontal=TRUE,
ylab="Free Wifi", xlab="Room Rent (INR)", las=1,
main="Comparison of Room Rent corresponding to Free Wifi")
boxplot(RoomRent ~ FreeBreakfast, data=AllCities.df, horizontal=TRUE,
ylab="Free Breakfast", xlab="Room Rent (INR)", las=1,
main="Comparison of Room Rent corresponding to Free Breakfast")
boxplot(RoomRent ~ HasSwimmingPool, data=AllCities.df, horizontal=TRUE,
ylab="Swimming Pool", xlab="Room Rent (INR)", las=1,
main="Comparison of Room Rent corresponding to Swimming Pool")
library(car)
scatterplot(HotelCapacity ~ RoomRent | IsTouristDestination, data =AllCities.df,
lwd=2, smooth=TRUE, span=0, cex=0.5,
xlab="Room Rent (INR)",
ylab="Hotel Capacity")
library(car)
scatterplot(Airport ~ RoomRent | IsTouristDestination, data =AllCities.df,
lwd=2, smooth=TRUE, span=0, cex=0.5,
xlab="Room Rent (INR)",
ylab="Hotel Capacity")
library(car)
scatterplot(StarRating ~ RoomRent | IsTouristDestination, data =AllCities.df,
lwd=2, smooth=TRUE, span=0, cex=0.5,
xlab="Room Rent (INR)",
ylab="Hotel Capacity")
library(car)
scatterplotMatrix(~ RoomRent + HotelCapacity + StarRating + Airport, data=AllCities.df,
main="Scatter Plot Matrix")
# creating a subset of dataframe of {RoomRent, HotelCapacity, StarRating and Airport}
x <- AllCities.df[,c("RoomRent", "HotelCapacity", "StarRating", "Airport")]
# correlation matrix stored in 'matrix'
matrix <- cor(x)
# round upto 2 decimal places
round(matrix, 2)
RoomRent HotelCapacity StarRating Airport
RoomRent 1.00 0.17 0.41 0.14
HotelCapacity 0.17 1.00 0.55 -0.11
StarRating 0.41 0.55 1.00 -0.05
Airport 0.14 -0.11 -0.05 1.00
library(corrgram)
corrgram(x, order=TRUE, lower.panel=panel.conf,
upper.panel=panel.pie, text.panel=panel.txt,
main="Corrgram of RoomRent, HotelCapacity, StarRating and Airport")