Hi everyone below is the code that I have in R Markdown which I'm having problems with:
daily_activity<- daily_activity %>% rename (ActivityDay= ActivityDate)
sleep_day<- sleep_day %>% rename (ActivityDay= SleepDay)
The error message that I'm getting is as followed:
Error in rename()
:
! Can't rename columns that don't exist.
Column ActivityDate
doesn't exist.
Run rlang::last_trace()
to see where the error occurred.
In my data frame there is a column named "Activity Date" as well as a column named "Sleep Day" and I'm trying to rename them. Can someone please tell me how to resolve the code error.
1 Like
"Activity Date" != ActivityDate
The space is the problem.
I addressed the spacing in the code and it's still giving me the same error message.
The error occurs because R is case-sensitive and also doesn’t handle spaces in column names well. Try using backticks or check column names with colnames(daily_activity)
. Modify your code like this:
daily_activity <- daily_activity %>% rename(`ActivityDay` = `Activity Date`)
sleep_day <- sleep_day %>% rename(`ActivityDay` = `Sleep Day`)
If the column names contain hidden spaces or special characters, use names(daily_activity)
to inspect them and clean them with janitor::clean_names()
.