0

I have a data frame called Covid19 and it contains a variable called Date. I want to create two new variables Month and Week from the Date variable. The output must look as in the image The code I wrote is :

Covid19_df <- Covid19_df$Date %>% mutate(Month = lubridate::month(date), 
                Week = lubridate::week(date))

but it gives an error

Error in UseMethod("mutate_") : 
  no applicable method for 'mutate_' applied to an object of class "Date"

Can anyone give me a possible solution or new code get the desired output.

Community
  • 1
  • 1
jonav
  • 3
  • 2

1 Answers1

1

The syntax that you were looking for is :

library(dplyr)

Covid19_df <- Covid19_df %>% 
                mutate(Month = lubridate::month(Date), 
                        Week = lubridate::week(Date))
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213