Import of fixed width data and col_type error

I have a dataset which looks like that

I want to change the col_type of the Date from character to date. But when I try I get an error.

northtemp <- read_table(file = "stasjonsdata-3.txt",
                         col_names = c("Location", "Date", "Hour", "Depth", "Temperature"),
                         col_types = cols(Date = col_date("%m.%Y")),
                         skip = 1)

I have done the same thing with data that is in .csv format. This is what I am trying to replicate

florida <- read_delim(file = "Florida-precip.csv", 
                      delim = ";",
                      locale = locale(decimal_mark = ","),
                      col_names = c("name", "station", "date", "precip"),
                      skip = 1, 
                      col_types = cols(date = col_date("%m.%Y")))

florida <- florida |> 
  mutate(
    month = month(date, label = TRUE), 
    year = year(date))
florida

florida |> 
  group_by(month) |> 
  summarise(precip = mean(precip)) |> 
  ggplot(aes(x = month, y = precip, fill = precip)) +
  geom_col() +
  labs(x = "", y = "Precipitation mm")

So does it work when it is in csv format? What does the error say? Can you provide a reproducible example?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.