tinytex::install_tinytex(force=TRUE)

#QUESTION 1

#Data frame is the tabular format in which data is stored in R. It has rows and columns. The type of data in columns should be the same. Data frame stores data in a structured manner which makes it easy to analyse. #mtcars is an example of dataframe in R. #my examples:

dataframe1 <- data.frame(
Name = c("Jon", "Elsa", "Bran"),
Age = c(25, 19, 17),
Gender = c("Male", "Female", "Male")
)
print(dataframe1)
##   Name Age Gender
## 1  Jon  25   Male
## 2 Elsa  19 Female
## 3 Bran  17   Male
dataframe2 <- data.frame(
ChargerType = c("A", "C", "Mini"),
Availability = c("Yes", "No", "Yes"),
Price = c(15, 10, 20)
)
print(dataframe2)
##   ChargerType Availability Price
## 1           A          Yes    15
## 2           C           No    10
## 3        Mini          Yes    20

#QUESTION 2

dataframe3 <- data.frame(
cars = c("Truck", "Car", "SUV"),
mpg = c(11, 30, 24),
cost = c(45000, 25000, 35000)
)
print(dataframe3)
##    cars mpg  cost
## 1 Truck  11 45000
## 2   Car  30 25000
## 3   SUV  24 35000

#QUESTION 2a

dataframe3[1,3]
## [1] 45000

#45000 is selected

dataframe3[1:3,]

#the whole dataframe is selected

dataframe3[ , 3]
## [1] 45000 25000 35000

#the cost column data is selected

#QUESTION 3

head(mtcars, n = 3)
tail(mtcars, n = 5)

#QUESTION 4

#categorical columns:

mtcars [ , c(8,10)]

#continuous columns:

mtcars [ , c(1,4)]

#QUESTION 5

library(ggplot2)

ggplot(mtcars, aes(x=disp, y=mpg))

#incomplete code as no geom function to specify

library(ggplot2)

ggplot(data=mtcars) + geom_point(mapping= aes(x=disp, y=mpg))

#updated code showing relationship between disp and mpg

#QUESTION 6

library(ggplot2)

ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy, color = cyl))

From the chart we can see that as the number of cylinders increase, the hwy mpg reduces. As the no. of cylinders reduce the hwy mpg increases. As cyl increases the engine displacement increases. And when the the no. of cyl reduces, the disp also reduces.

#QUESTION 7

library(ggplot2)

ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy, color = cyl)) +
facet_wrap(~drv, nrow =2)

#With Rear wd has less cylinders with more engine disp. f has lesser engine disp and 4 wd is spread out for engine disp.