Usage of weekdays

I tried to create new variables from my data set. This is what I typed:

dt4w05S <- read.csv("w05S.csv")
dt4w05S <- dt4w05S %>%
mutate(productPriceUnit = RetailPriceUnit/1.13,
productType =
Revenue = SalesQuantityproductPriceUnit,
productCost = SalesQuantity
grossProfit = Revenue - productCost,
Day = weekdays(SalesDate))

Then it said: Error in UseMethod("weekdays") :
no applicable method for 'weekdays' applied to an object of class "factor"

Anyone knows how to fix this?
Thank you.

Hard to tell for sure without a reproducible example, but very likely the problems is that read.csv() is reading SalesDate as factors instead of dates, use read_csv() instead, if you need more specific help, please provide a proper REPRoducible EXample (reprex)

This error means that you apply the function weekdays on a variable of type factor but this function is made to work on Dates. see ?weekdays
you need to correctly prepare your data I guess

Hi JimmyKuo,

Please share some sample dates from your data. That should help us understand and troubleshoot.

From what I can make out from the error, you need to first convert the date from factor to a date time object. We can help you if you can share some sample dates from your dataset.

Warm Regards,

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