I am still relatively new to R and any tips would be appreciated
So I want to parse the time for specific dataframes and what I've tried to do was create a list and adjust the names accordingly.
mydir = "Data/Fitabase_Data_4.12.16-5.12.16"
csvfiles = list.files(path = mydir, pattern ="*.csv", full.names = TRUE)
# Create list of names without ".csv".
names <-substr(csvfiles, 36, 100)
names <- gsub("\\.csv", "", names)
# Create for loop to individually read each .csv.
for(i in names){
filepath <- file.path("Data/Fitabase_Data_4.12.16-5.12.16", paste(i, ".csv", sep = ""))
assign(i, read.csv(filepath))
}
hourlyfiles = list.files(path = mydir, pattern = "hourly*", full.names = TRUE)
hourlyfiles <- gsub("Data/Fitabase_Data_4.12.16-5.12.16/", "", hourlyfiles)
hourlyfiles <- gsub("\\.csv", "$ActivityHour", hourlyfiles)
Below is the first three rows of one of the tables and I am trying to parse the date and time in order to upload the dataset somewhere else.
Id | ActivityHour | Calories |
---|---|---|
1503960366 | 4/12/2016 12:00:00 AM | 81 |
1503960366 | 4/12/2016 1:00:00 AM | 61 |
1503960366 | 4/12/2016 2:00:00 AM | 59 |
The code below returns an error: "All formats failed to parse. No formats found."
# Create for loop to parse each file
for(i in hourlyfiles){
parse_date_time(i, "%m/%d/$y %I:%M:%S %p")
}