#1 Which traffic sign appears most frequently in the dataset?
traffic_signs <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

head(traffic_signs)
##   ClassId                 Name
## 1       0  Speed limit (5km/h)
## 2       1 Speed limit (15km/h)
## 3       2 Speed limit (30km/h)
## 4       3 Speed limit (40km/h)
## 5       4 Speed limit (50km/h)
## 6       5 Speed limit (60km/h)
summary(traffic_signs)
##     ClassId          Name          
##  Min.   : 0.00   Length:52         
##  1st Qu.:12.75   Class :character  
##  Median :25.50   Mode  :character  
##  Mean   :25.50                     
##  3rd Qu.:38.25                     
##  Max.   :51.00
sign_counts <- table(traffic_signs$traffic_sign_type)
most_frequent_sign <- names(sign_counts)[which.max(sign_counts)]

print(most_frequent_sign)
## NULL
# 2 Distribution of different types of traffic signs in the dataset?
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)

traffic_signs <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

traffic_sign_distribution <- table(traffic_signs$Name)

distribution_df <- data.frame(
  sign_category = names(traffic_sign_distribution),
  count = as.numeric(traffic_sign_distribution)
)

distribution_df <- distribution_df %>%
  arrange(desc(count))

ggplot(distribution_df, aes(x = reorder(sign_category, count), y = count)) +
  geom_bar(stat = "identity", fill = "skyblue", color = "black") +
  theme_minimal() +
  labs(x = "Traffic Sign Category", y = "Frequency", title = "Distribution of Traffic Sign Categories") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))  

# 3 Which traffic sign categories are the most common and least common?
library(dplyr)

traffic_signs <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

traffic_sign_frequency <- traffic_signs %>%
  count(Name) %>%
  arrange(desc(n))

cat("Most common traffic sign categories:\n")
## Most common traffic sign categories:
print(traffic_sign_frequency[1:5, ])
##                           Name n
## 1            Bicycles crossing 2
## 2            Children crossing 1
## 3                 Danger Ahead 1
## 4  Dangerous curve to the left 1
## 5 Dangerous curve to the right 1
cat("\nLeast common traffic sign categories:\n")
## 
## Least common traffic sign categories:
print(traffic_sign_frequency[nrow(traffic_sign_frequency): (nrow(traffic_sign_frequency) - 4), ])
##                    Name n
## 51   watch out for cars 1
## 50 speed limit (80km/h) 1
## 49           keep Right 1
## 48            keep Left 1
## 47         ZigZag Curve 1
# 4 Are there any underrepresented traffic sign categories in the dataset?
library(dplyr)

traffic_signs <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

traffic_sign_frequency <- traffic_signs %>%
  count(Name) %>%
  arrange(n)

cat("Underrepresented traffic sign categories:\n")
## Underrepresented traffic sign categories:
print(traffic_sign_frequency[1:5, ])
##                           Name n
## 1            Children crossing 1
## 2                 Danger Ahead 1
## 3  Dangerous curve to the left 1
## 4 Dangerous curve to the right 1
## 5                 Dont Go Left 1
# 5 How many traffic sign categories contain the word "Unknown"?
library(dplyr)

traffic_signs_data <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

unknown_signs_count <- traffic_signs_data %>%
  filter(grepl("Unknown", Name, ignore.case = TRUE)) %>%
  nrow()

print(unknown_signs_count)
## [1] 7
# 6 How many traffic sign categories include the word "speed limit"?
library(dplyr)

traffic_signs_data <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

speed_limit_signs_count <- traffic_signs_data %>%
  filter(grepl("speed limit", Name, ignore.case = TRUE)) %>%
  nrow()

print(speed_limit_signs_count)
## [1] 8
# 7 What is the distribution of traffic signs based on their positional instructions (e.g., left, right, straight)?

library(dplyr)

traffic_signs_data <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

positional_instructions <- c("Left", "Right", "Straight")

positional_instruction_counts <- data.frame(Positional_Instruction = positional_instructions,
                                            Count = rep(0, length(positional_instructions)))

for (instruction in positional_instructions) {
  positional_instruction_counts$Count[instruction == "Left" | instruction == "Right" | instruction == "Straight"] <-
    sum(grepl(instruction, traffic_signs_data$Name, ignore.case = TRUE))
}

print(positional_instruction_counts)
##   Positional_Instruction Count
## 1                   Left     6
## 2                  Right     6
## 3               Straight     6
# 8 Are there any traffic sign categories indicating specific hazards or dangers?
library(dplyr)

traffic_signs_data <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

hazard_keywords <- c("Danger", "Hazard", "Warning")

hazard_signs <- traffic_signs_data %>%
  filter(grepl(paste(hazard_keywords, collapse = "|"), Name, ignore.case = TRUE))

print(unique(hazard_signs$Name))
## [1] "Danger Ahead"                 "Dangerous curve to the left" 
## [3] "Dangerous curve to the right"
# 9 How many traffic sign categories are related to railway crossings?
library(dplyr)

traffic_signs_data <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

railway_crossing_keywords <- c("Train Crossing", "Railway Crossing")

railway_crossing_signs <- traffic_signs_data %>%
  filter(grepl(paste(railway_crossing_keywords, collapse = "|"), Name, ignore.case = TRUE))

num_railway_crossing_signs <- nrow(railway_crossing_signs)

print(num_railway_crossing_signs)
## [1] 1
# 10 Are there any traffic sign categories indicating temporary conditions or construction?
library(dplyr)

traffic_signs_data <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

construction_keywords <- c("Under Construction", "Construction", "Temporary")

construction_signs <- traffic_signs_data %>%
  filter(grepl(paste(construction_keywords, collapse = "|"), Name, ignore.case = TRUE))

print(unique(construction_signs$Name))
## [1] "Under Construction"
# 11 Are there any duplicate traffic sign categories in the dataset?
library(dplyr)

traffic_signs_data <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

duplicate_signs <- traffic_signs_data %>%
  group_by(Name) %>%
  summarise(count = n()) %>%
  filter(count > 1)

print(duplicate_signs)
## # A tibble: 1 × 2
##   Name              count
##   <chr>             <int>
## 1 Bicycles crossing     2
# 12 What is the proportion of traffic signs indicating mandatory actions?


library(dplyr)

traffic_signs_data <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

mandatory_keywords <- c("mandatory", "must")

mandatory_signs_count <- traffic_signs_data %>%
  filter(grepl(paste(mandatory_keywords, collapse = "|"), Name, ignore.case = TRUE)) %>%
  nrow()

total_signs_count <- nrow(traffic_signs_data)

proportion_mandatory <- mandatory_signs_count / total_signs_count

print(proportion_mandatory)
## [1] 0.01923077
# 13 How many traffic sign categories contain the word "curve"?


library(dplyr)

traffic_signs_data <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

curve_signs_count <- traffic_signs_data %>%
  filter(grepl("curve", Name, ignore.case = TRUE)) %>%
  nrow()

print(curve_signs_count)
## [1] 3
# 14 How many traffic sign categories are related to pedestrian crossings?
library(dplyr)

traffic_signs_data <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

pedestrian_crossing_keywords <- c("pedestrian crossing", "crosswalk", "zebra crossing")

pedestrian_crossing_signs <- traffic_signs_data %>%
  filter(grepl(paste(pedestrian_crossing_keywords, collapse = "|"), Name, ignore.case = TRUE))

num_pedestrian_crossing_signs <- nrow(unique(pedestrian_crossing_signs))

print(num_pedestrian_crossing_signs)
## [1] 1
 # 15 How many traffic sign categories are related to parking regulations ?
library(dplyr)

traffic_signs_data <- read.csv("C:/Users/Vivek singh/Downloads/labels.csv")

parking_keywords <- c("parking", "no parking", "park", "no park")

parking_signs <- traffic_signs_data %>%
  filter(grepl(paste(parking_keywords, collapse = "|"), Name, ignore.case = TRUE))

num_parking_signs <- nrow(unique(parking_signs))

print(num_parking_signs)
## [1] 0