stions R to find answers to all of the following questions (that is, don\'t do a
ID: 3359669 • Letter: S
Question
stions R to find answers to all of the following questions (that is, don't do any by hand or by point-and-click your code in an R script. . Write a function that loads the Bay Area bike share trip data from a CSV file, converts the columns to appropriate data types, and then saves the tidied data frame to an RDS file. Your function should have arguments to set the path for the input CSV file and the output RDS file. Write a second function that does the same thing for the Bay Area bike share station data.Explanation / Answer
Below is the function to load a csv file and save it into RDS format. Change your file name (TripData.csv) in the code.
LoadSave.Trip = function(input.dir, output.dir) {
setwd(input.dir) # Set the working directory to read and load the file
df = read.csv("TripData.csv", header = TRUE) #Chnage the header option to FALSE, if there are no headers
df$fieldname = as.character(df$fieldname) #Do this for all characters fields
df$fieldname = as.numeric(df$fieldname) #Do this for all numeric fields
setwd(output.dir) # Set the working directory to save the file
saveRDS(df, file="Trip.Rda")
}
Similarly,
Below is the function to load a csv file and save it into RDS format. Change your Station data file name (StationData.csv) in the code.
LoadSave.Station = function(input.dir, output.dir) {
setwd(input.dir) # Set the working directory to read and load the file
df = read.csv("StationData.csv", header = TRUE) #Chnage the header option to FALSE, if there are no headers
df$fieldname = as.character(df$fieldname) #Do this for all characters fields
df$fieldname = as.numeric(df$fieldname) #Do this for all numeric fields
setwd(output.dir) # Set the working directory to save the file
saveRDS(df, file="Station.Rda")
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.