Stats 101A HW1

.Rmd

School

University of California, Los Angeles *

*We aren’t endorsed by this school

Course

101A

Subject

Statistics

Date

Jan 9, 2024

Type

Rmd

Pages

2

Uploaded by ucladsp

--- title: "Stats 101A HW1" author: 'Ian Zhang, UID: 205702810' date: "4/5/2023" output: pdf_document: default html_document: default --- ## Question 1 ```{r Question 1} library(tidyverse) library(lubridate) chi <- read.csv("chicagotaxiraw.csv") chi1<- chi %>% select('Trip.ID', 'Taxi.ID', 'Trip.Start.Timestamp', 'Trip.End.Timestamp', 'Trip.Seconds', 'Trip.Miles', 'Fare', 'Tips', 'Tolls', 'Extras', 'Trip.Total', 'Payment.Type','Company') %>% rename(trip.id = 'Trip.ID', taxi.id = 'Taxi.ID', trip.start.timestamp = 'Trip.Start.Timestamp', trip.end.timestamp = 'Trip.End.Timestamp', trip.seconds = 'Trip.Seconds', trip.miles = 'Trip.Miles', fare = 'Fare', tips = 'Tips', tolls = 'Tolls', extras = 'Extras', trip.total = 'Trip.Total', payment.type = 'Payment.Type', company = 'Company') ``` ## Question 2 ```{r Question 2} endDate <- as.Date((chi1$trip.end.timestamp), format = "%Y-%m-%d %H:%M:%S") #First pickup max(endDate, na.rm=TRUE) #Last pickup min(endDate, na.rm = TRUE) ``` ## Question 3 ```{r Question 3} table(wday(as.Date((chi1$trip.start.timestamp), format = "%Y-%m-%d %H:%M:%S"))) max(table(wday(as.Date((chi1$trip.start.timestamp), format = "%Y-%m-%d %H:%M: %S")))) #Saturday has the greatest number of trips begin with 16767 trips min(table(wday(as.Date((chi1$trip.start.timestamp), format = "%Y-%m-%d %H:%M: %S")))) #Tuesday has the least number of trips begin with 12406 ``` ## Question 4 ``` {r Question 4} fix <- function(x){ x2 <- gsub("\\$","",x) as.numeric(as.character(gsub(",", "", x2))) } tip <- sapply(chi1$tips, fix) summary(tip) hist(tip) #The mean amount of a tip is $1.15, but the median is $0.00. It is better to report the median #rather than the mean, since the data is extremely skewed,
#and has outliers that pull the mean away from what the typical tip amount is, thus the typical #tip amount would be $0.00 ```
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help