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.
1 Like
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()
.
It seems that my problems are stemming from the fact that I haven't loaded the packages into Rmd. When I went to load the appropriate packages in I'm getting the following message:
library(tidyr)
library(tidyverse)
library(purrr)
library(readr)
library(dbplyr)
library(magrittr)
ββ Attaching core tidyverse packages ββββββββββββββββββββββββββββββββββββββββ tidyverse 2.0.0 ββ
dplyr 1.1.4
purrr 1.0.2
forcats 1.0.0
readr 2.1.5
ggplot2 3.5.1
stringr 1.5.1
lubridate 1.9.4
tibble 3.2.1
ββ Conflicts ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ tidyverse_conflicts() ββ
dplyr::filter() masks stats::filter()
dplyr::lag() masks stats::lag()
Use the conflicted package to force all conflicts to become errors
Registered S3 methods overwritten by 'dbplyr':
method from
print.tbl_lazy
print.tbl_sql
Attaching package: βdbplyrβ
The following objects are masked from βpackage:dplyrβ:
ident, sql
Attaching package: βmagrittrβ
The following object is masked from βpackage:purrrβ:
set_names
The following object is masked from βpackage:tidyrβ:
extract
WHAT DOES ALL THIS MEAN?
The messages inform you that there are functions with the same names in different packages and inform you which take precedence (due to the order of loading the packages).
1 Like
Thanks so much for your help!