I have created a Kaggle notebook using R code and R Markdown together. I am facing this error-
**Error in UseMethod("mutate"): no applicable method for 'mutate' applied to an object of class "character" Traceback:
-whenever I am trying to run all the codes together.
The codes are working perfectly individually. I simply wanted to use R codes and R markdown together. Instead of using R Markdown directly, I used R notebook, and then this happened.
The link to my Kaggle notebook is here.
Please help me sort this issue as I am struggling since morning with this.
[Also, according to what I have understood - I am thinking that there is a problem of using R MarkDown and R code together, maybe I have not used them together correctly. Kindly correct me if I am wrong. Thanks.]
I assume it has nothing do with R Markdown.
I created a kaggle account and downloaded your data dailyActivity_merged.csv
. For reproducibility I have uploaded the first ten rows.
After this line
daily_activities$activity_date <- as.POSIXct(daily_activities$ActivityDate,
format="%m/%d/%Y",
tz = Sys.timezone())
consider to change your code to either of the following
{dplyr}
syntaxdaily_activities |>
dplyr::mutate(DayOfWeek = weekdays(activity_date))
base R
daily_activities$DayOfWeek <- weekdays(daily_activities$activity_date)
You may change the variable names accordingly.
Data
daily_activities10 <- structure(list(Id = c(1503960366, 1503960366, 1503960366, 1503960366,
1503960366, 1503960366), ActivityDate = c("4/12/2016", "4/13/2016",
"4/14/2016", "4/15/2016", "4/16/2016", "4/17/2016"), TotalSteps = c(13162L,
10735L, 10460L, 9762L, 12669L, 9705L), TotalDistance = c(8.5,
6.96999979019165, 6.73999977111816, 6.28000020980835, 8.15999984741211,
6.48000001907349), TrackerDistance = c(8.5, 6.96999979019165,
6.73999977111816, 6.28000020980835, 8.15999984741211, 6.48000001907349
), LoggedActivitiesDistance = c(0, 0, 0, 0, 0, 0), VeryActiveDistance = c(1.87999999523163,
1.57000005245209, 2.44000005722046, 2.14000010490417, 2.71000003814697,
3.19000005722046), ModeratelyActiveDistance = c(0.550000011920929,
0.689999997615814, 0.400000005960464, 1.25999999046326, 0.409999996423721,
0.779999971389771), LightActiveDistance = c(6.05999994277954,
4.71000003814697, 3.91000008583069, 2.82999992370605, 5.03999996185303,
2.50999999046326), SedentaryActiveDistance = c(0, 0, 0, 0, 0,
0), VeryActiveMinutes = c(25L, 21L, 30L, 29L, 36L, 38L), FairlyActiveMinutes = c(13L,
19L, 11L, 34L, 10L, 20L), LightlyActiveMinutes = c(328L, 217L,
181L, 209L, 221L, 164L), SedentaryMinutes = c(728L, 776L, 1218L,
726L, 773L, 539L), Calories = c(1985L, 1797L, 1776L, 1745L, 1863L,
1728L)), row.names = c(NA, 6L), class = "data.frame")