When I import my data into R it is truncated.
For example the raw data is 01:35.2 when I look in Microsoft Excel but it shows in the column as 01:35:00.
I've included the packages I've used below.
Please note, I've left this data in a de-identified format as it's for research.
## Load libraries
lapply(c("tidyverse", "readxl", "cowplot", "psych", "lubridate", "hms", "here"), library, character.only = TRUE)
## Set relative path
file <- here("7-stroke, 20-Second, 60-Second & 2,000-meter_Master File Deidentified.csv")
file.exists(file)
## Import data
KUWRowPowerDF <- read_csv(file)
View(dput(head(KUWRowPowerDF, 5)))
giving this output
structure(list(ID = c("KUWROW001", "KUWROW002", "KUWROW003", "KUWROW004", "KUWROW005")
`20-Second_Split`= structure(c(5700, 5880, 5640, 5820, 5940), class = c("hms", "difftime"), units = "secs"),
`60-Second_Split`= structure(c(5940, 6000, 5820, 5820, 6060), class = c("hms", "difftime"), units = "secs"),
`2k_Avg_Split`= structure(c(6960, 6900, 6720, 6900, 6720), class = c("hms", "difftime"), units = "secs"),
`2k_Max_Split`= structure(c(6300, 6060, 6360, 6360, 6180), class = c("hms", "difftime"), units = "secs"),
`2k_Total_Time_min` = structure(c(27840,27720, 26940, 27600, 27000), class = c("hms", "difftime"), units = "secs")
I can reproduce this issue by making a CSV that is just
time
1:35.2
which read_csv reads in as time = structure(5700, class = c("hms", "difftime"), units = "secs")
but read.csv reads in as time = "1:35.2" (character)
.
This looks to me like a read_csv
bug, and there is an open issue here: github.com/tidyverse/readr/issues/1095
In the meantime, you could address this by reading in using either read.csv
or read_csv
specifying col_types
as character. Once loaded, you can convert the text to fractional-second times using, e.g. df |> mutate(time = lubridate::ms(time)
to convert it to time durations like "1M 35.2S"
.