BAN - Business Analytics

Lab 1 - Cycling in Austin

Loading the Data

BikeData <- read.csv("./BikeData.csv")

Analysing the Data

1.1. What is the age of the 7th rider in the dataset?

message("Age of Cyclist 7: ",appendLF=FALSE) 
## Age of Cyclist 7:
BikeData$age[7]
## [1] 45

1.2. How many of the first 10 riders in the dataset ride daily?

message("Answer: ",appendLF=FALSE) 
## Answer:
FirstTen <- head(BikeData,10)
nrow(FirstTen[FirstTen$cyc_freq == 'Daily',])
## [1] 3

1.3. What is the speed of the first female who cycles less than one time per month (in miles/hour)?

Females <- BikeData[BikeData$gender == 'F',]
Lazy <- Females[Females$cyc_freq == 'Less than once a month',]

message("Average speed (miles/hour): ",appendLF=FALSE)  
## Average speed (miles/hour):
Lazy$speed[1]
## [1] 8.1

2.1. What type of variable is student?

typeof(BikeData$student)
## [1] "integer"

OBS. In fact is a binary variable that may assume 2 values, 1 for studant or 0 for other.

2.2. What type of variable is cyc_freq?

typeof(BikeData$cyc_freq)
## [1] "integer"

OBS. In fact is a categorical variable that may assume 4 diferent values that internaly in R is represented as an integer.

2.3. What type of variable is distance?

typeof(BikeData$distance)
## [1] "double"

OBS. Is a numerical value.

3. In this lab, we will be creating a new dataset that includes just the student riders and all of their variables. What is the correct terminology for this new data set?

Answer: data frame

4.1. How many of the cyclists were students?

message("Numeber of Studants: ",appendLF=FALSE)
## Numeber of Studants:
Studants <- BikeData[BikeData$student == '1',] 
nrow(Studants)
## [1] 14

4.2. How often did they ride?

table(Studants$cyc_freq)
## 
##                   Daily  Less than once a month Several times per month 
##                       8                       0                       0 
##  Several times per week 
##                       6

4.3. What was the average distance they rode?

message("Average Distance: ",appendLF=FALSE)
## Average Distance:
mean(Studants$distance)
## [1] 6.257857

Conclusion

In this lab, we examined data on 14 student riders. Most of the student riders (a total of 8 out of 14 ) rode their bikes daily. On average, the students rode about 6.25 miles on each trip.