Q4 Task: Import the bike sharing dataset into R using base R functions and store it as a data frame.

bike4 <- read.delim("bike_sharing_data.txt")

bike2 <- read.table("bike_sharing_data.txt", sep="\t", header=TRUE)

bike1 <- read.table("bike_sharing_data.csv", sep=",", header=TRUE)

bike3 <- read.csv("bike_sharing_data.csv")

Q5 Task: Determine the total number of observations (rows) and variables (columns) in the bike sharing dataset.

bike_sharing_data <- read.csv("bike_sharing_data.csv")
dim(bike_sharing_data)
## [1] 17379    13

Q6 Task: Examine the data type of the humidity variable as interpreted by R after importing the dataset using base R functions.

str(bike_sharing_data$humidity)
##  chr [1:17379] "81" "80" "80" "75" "75" "75" "80" "86" "75" "76" "76" "81" ...

Q7 Task: Retrieve the value of the season variable for the observation in row 6251 using indexing.

bike_sharing_data[6251, "season"]
## [1] 4

Q8 Task: Count the number of observations that correspond to the winter season in the dataset.

table(bike_sharing_data$season)
## 
##    1    2    3    4 
## 4242 4409 4496 4232

Note: In the dataset, the season variable is coded as follows: 1 = Fall, 2 = Spring, 3 = Summer, 4 = Winter.

Q9 Task: Demonstrate how to subset a data frame using multiple logical conditions and the %in% operator.

df <- data.frame(season = c("winter","summer","winter"), wind = c(10, 30, 25))
df[df$season == "winter" & df$wind > 20, ]
##   season wind
## 3 winter   25
df[df$season %in% c("winter", "fall"), ]
##   season wind
## 1 winter   10
## 3 winter   25

Q10 Task: Determine the number of observations that have high wind speed conditions and occur during the winter or spring seasons.

count_high_wind <- sum(
  bike_sharing_data$windspeed >= 40 & bike_sharing_data$windspeed <= 57 &
  bike_sharing_data$season %in% c(1, 4),
  na.rm = TRUE
)

count_high_wind
## [1] 46