Error in sorting a df import from csv file

##CSV file df date column separate to year and month columns.

Error: arrange() failed at implicit mutate() step.

  • Problem with mutate() column ..1.
    i ..1 = Month.
    x object 'Month' not found
    Run rlang::last_error() to see where the error occurred.

The error message is quite explicit. It couldn't find Month in your dataset.

Without a sample of your data neither can we!

Can you provide a head( )?.
Can you provide a reprex?

If you can see Month (not month) as a column my gut feeling is there may be a rogue character that doesn't display on screen but is in the name. Janitor could be your friend. But I'm speculating...

The other time I see this is when I stupidly forget to pass my data to the mutate function!

1 Like
library(tidyr)
setwd("D:\\time series assignment")

dir()
data=read.csv("data.CSV")
head(data)

data %>%

separate(Year..Month, into = c('Year', 'Month'), sep = '-') %>%
  select(Year,Month,Tea.Production)


library(dplyr)

  head(df)
str(df)

df=arrange(df,Month,Tea.Production)

Initial dataframe from csv file

modified data frame. I need to sort this data set according to month. All January values together and all February values together. likewise

df %>% arrange(Month)
1 Like

Do you need the months to go in the correct order and the year too?

Basically i need to convert imported csv file df to tsibble

OK. Would it be better... to us as_tisbble by converting year..month to a proper date?

library(tidyr)
require(tsibble
setwd("D:\\time series assignment")

data=read.csv("data.CSV")


data %>%
mutate(YearMonth = as.Date(Paste 0(Year..Month,"-01")) %>%
as_tsibble(index=YearMonth, key=Tea.Production)