# Question 4: Importing the Bike Sharing Datasets
# Option A: Read CSV using read.table()
bike1 <- read.table("bike_sharing_data.csv", sep=",", header=TRUE)
# Option B: Read CSV using read.csv()
bike3 <- read.csv("bike_sharing_data.csv")
# Option C: Read TXT using read.table()
bike2 <- read.table("bike_sharing_data.txt", sep="\t", header=TRUE)
# Option D: Read TXT using read.delim()
bike4 <- read.delim("bike_sharing_data.txt")
# Check that the datasets imported correctly
head(bike1)
## datetime season holiday workingday weather temp atemp humidity
## 1 1/1/2011 0:00 1 0 0 1 9.84 14.395 81
## 2 1/1/2011 1:00 1 0 0 1 9.02 13.635 80
## 3 1/1/2011 2:00 1 0 0 1 9.02 13.635 80
## 4 1/1/2011 3:00 1 0 0 1 9.84 14.395 75
## 5 1/1/2011 4:00 1 0 0 1 9.84 14.395 75
## 6 1/1/2011 5:00 1 0 0 2 9.84 12.880 75
## windspeed casual registered count sources
## 1 0.0000 3 13 16 ad campaign
## 2 0.0000 8 32 40 www.yahoo.com
## 3 0.0000 5 27 32 www.google.fi
## 4 0.0000 3 10 13 AD campaign
## 5 0.0000 0 1 1 Twitter
## 6 6.0032 0 1 1 www.bing.com
head(bike2)
## datetime season holiday workingday weather temp atemp humidity
## 1 1/1/2011 0:00 1 0 0 1 9.84 14.395 81
## 2 1/1/2011 1:00 1 0 0 1 9.02 13.635 80
## 3 1/1/2011 2:00 1 0 0 1 9.02 13.635 80
## 4 1/1/2011 3:00 1 0 0 1 9.84 14.395 75
## 5 1/1/2011 4:00 1 0 0 1 9.84 14.395 75
## 6 1/1/2011 5:00 1 0 0 2 9.84 12.880 75
## windspeed casual registered count sources
## 1 0.0000 3 13 16 ad campaign
## 2 0.0000 8 32 40 www.yahoo.com
## 3 0.0000 5 27 32 www.google.fi
## 4 0.0000 3 10 13 AD campaign
## 5 0.0000 0 1 1 Twitter
## 6 6.0032 0 1 1 www.bing.com
head(bike3)
## datetime season holiday workingday weather temp atemp humidity
## 1 1/1/2011 0:00 1 0 0 1 9.84 14.395 81
## 2 1/1/2011 1:00 1 0 0 1 9.02 13.635 80
## 3 1/1/2011 2:00 1 0 0 1 9.02 13.635 80
## 4 1/1/2011 3:00 1 0 0 1 9.84 14.395 75
## 5 1/1/2011 4:00 1 0 0 1 9.84 14.395 75
## 6 1/1/2011 5:00 1 0 0 2 9.84 12.880 75
## windspeed casual registered count sources
## 1 0.0000 3 13 16 ad campaign
## 2 0.0000 8 32 40 www.yahoo.com
## 3 0.0000 5 27 32 www.google.fi
## 4 0.0000 3 10 13 AD campaign
## 5 0.0000 0 1 1 Twitter
## 6 6.0032 0 1 1 www.bing.com
head(bike4)
## datetime season holiday workingday weather temp atemp humidity
## 1 1/1/2011 0:00 1 0 0 1 9.84 14.395 81
## 2 1/1/2011 1:00 1 0 0 1 9.02 13.635 80
## 3 1/1/2011 2:00 1 0 0 1 9.02 13.635 80
## 4 1/1/2011 3:00 1 0 0 1 9.84 14.395 75
## 5 1/1/2011 4:00 1 0 0 1 9.84 14.395 75
## 6 1/1/2011 5:00 1 0 0 2 9.84 12.880 75
## windspeed casual registered count sources
## 1 0.0000 3 13 16 ad campaign
## 2 0.0000 8 32 40 www.yahoo.com
## 3 0.0000 5 27 32 www.google.fi
## 4 0.0000 3 10 13 AD campaign
## 5 0.0000 0 1 1 Twitter
## 6 6.0032 0 1 1 www.bing.com
# Question 6: Check the data type of humidity
class(bike1$humidity)
## [1] "character"
# Question 7: Find the season value in row 6251
bike1[6251, "season"]
## [1] 4
# Question 8: Count observations for each season
table(bike1$season)
##
## 1 2 3 4
## 4242 4409 4496 4232
# Question 10: Count high wind observations during winter or spring
sum(bike1$season %in% c(1, 4) &
as.numeric(as.character(bike1$windspeed)) >= 40,
na.rm = TRUE)
## [1] 46