Cargando archivo

CARS_1 <- read.csv("E:/TRABAJO/2024/R studio/CARS_1.csv")

Explorando datos

str(CARS_1)
## 'data.frame':    203 obs. of  17 variables:
##  $ car_name           : chr  "Maruti Alto K10" "Maruti Brezza" "Mahindra Thar" "Mahindra XUV700" ...
##  $ reviews_count      : int  51 86 242 313 107 99 731 381 107 205 ...
##  $ sold.or.rent       : chr  "sold" "sold" "sold" "sold" ...
##  $ fuel_type          : chr  "Petrol" "Petrol" "Diesel" "Diesel" ...
##  $ engine_displacement: int  998 1462 2184 2198 2198 2755 1493 1199 1498 1197 ...
##  $ no_cylinder        : int  3 4 4 4 4 4 4 3 3 4 ...
##  $ seating_capacity   : int  5 5 4 7 7 7 5 5 7 5 ...
##  $ transmission_type  : chr  "Automatic" "Automatic" "Automatic" "Automatic" ...
##  $ fuel_tank_capacity : num  27 48 57 60 57 80 50 37 60 37 ...
##  $ body_type          : chr  "Hatchback" "SUV" "SUV" "SUV" ...
##  $ rating             : num  4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4 ...
##  $ starting_price     : int  399000 799000 1353000 1318000 1199000 3240000 1044000 593000 933000 592000 ...
##  $ ending_price       : int  583000 1396000 1603000 2458000 2390000 4957000 1818000 949000 1026000 885000 ...
##  $ max_torque_nm      : num  89 137 300 450 400 ...
##  $ max_torque_rpm     : int  3500 4400 2800 2800 2750 2800 2750 3400 2200 4400 ...
##  $ max_power_bhp      : num  65.7 101.7 130 182.4 172.4 ...
##  $ max_power_rp       : int  5500 6000 3750 3500 3500 3400 4000 6000 3600 6000 ...

Utilizando funciones y describiendo lo que se realiza

#Vargamos librerias 

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(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.4
## ✔ ggplot2   3.4.3     ✔ stringr   1.5.0
## ✔ lubridate 1.9.2     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# Filter: Filtrar datos
filtered_data <- filter(CARS_1, transmission_type == "Automatic")
head(filtered_data)
# Arrange: Ordenar datos
arranged_data <- arrange(CARS_1, desc(rating))
head(arranged_data)
# Select: Seleccionar columnas
selected_data <- select(CARS_1, car_name, fuel_type, rating)
head(selected_data)
# Mutate: Crear nuevas variables
mutated_data <- mutate(CARS_1, price_per_cylinder = starting_price / no_cylinder)
head(mutated_data)
# Group_by: Agrupar datos
grouped_data <- group_by(CARS_1, fuel_type)
summary_data <- summarise(grouped_data, avg_rating = mean(rating), max_price = max(ending_price))
head(summary_data)
# NAs: Manejar valores perdidos
na_filtered_data <- na.omit(CARS_1)
head(na_filtered_data)

Obtener estadisticas

promedio <- mean(CARS_1$rating)
print(promedio)
## [1] 4.433498
suma <- sum(CARS_1$reviews_count)
print(suma)
## [1] 24093
mediana <- median(CARS_1$engine_displacement)
print(mediana)
## [1] 1991
desviacion_estandar <- sd(CARS_1$seating_capacity)
print(desviacion_estandar)
## [1] NA
varianza <- var(CARS_1$rating)
print(varianza)
## [1] 0.07847632

Preguntas de investigación

# Pregunta 1: ¿Cuántos autos se ofrecen para venta y cuántos para alquiler?
venta_alquiler_counts <- table(CARS_1$sold)
print(venta_alquiler_counts)
## 
## rent sold 
##  121   82
# Pregunta 2: ¿Cuál es la suma total de revisiones de los autos automáticos?
suma_revisiones_automaticos <- sum(filter(CARS_1, transmission_type == "Automatic")$reviews_count)
print(suma_revisiones_automaticos)
## [1] 18354
# Pregunta 3: ¿Cuál es la calificación promedio de los autos de cuerpo tipo "Sedan"?
promedio_calificacion_sedan <- mean(filter(CARS_1, body_type == "Sedan")$rating)
print(promedio_calificacion_sedan)
## [1] 4.465116
# Pregunta 4: ¿Cuál es la mediana de la capacidad de asientos de los autos de combustible Diesel?
mediana_asientos_diesel <- median(filter(CARS_1, fuel_type == "Diesel")$seating_capacity)
print(mediana_asientos_diesel)
## [1] 5
# Pregunta 5: ¿Cuál es la diferencia promedio entre el precio inicial y final de los autos con más de 4 cilindros?
diferencia_promedio_precios_cilindros <- mean(mutate(filter(CARS_1, no_cylinder > 4), price_difference = ending_price - starting_price)$price_difference)
print(diferencia_promedio_precios_cilindros)
## [1] 3423625