Hi,
I have this simple df:
source <- data.frame(
stringsAsFactors = FALSE,
URN = c("aaa","bbb","ccc",
"ddd","eee","fff","ggg","hhh"),
Name = c("xxx","xxx","yyy",
"yyy","yyy","zzzz","abcde","zzzz"),
A1 = c("None.",NA,
"No comments related to this exercise","Na",
"N/A","Interesting comment","abc", "whatever is fine"),
A2 = c("Nothing",
"I have nothing in common","NA",NA,
"Another comment","....?","xxxx", "All fine"),
B1 = c("Service","All good",
"aa"," I don't know",
"The final comment about that","Nothing.","na","Everything"),
B2 = c("aaa","Nothing ",
"None","My final comments are ok", "I don't know ",
"Nothing.","Another comment","really"),
Q4 = c(2019,2020,2020,2019,
2020,2021,2021,2019)
)
where I applied this function:
renamed <- rename_with(source,
.fn=~paste0("Comm",.),
.cols=where(~is.character(.x) &
any(nchar(.x) > 15)))
renamed
It works well so now I am trying to apply it to my real, large df (to large to be here) with following variables:
'data.frame': 27641 obs. of 131 variables:
$ BranchID : int 35049916 35049916 35049916 35049916 35049916 35049916 35049916 35049916 35049916 35049916 ...
$ Country_Name : chr "xxx" "xxx" "xxx" "xxx" ...
$ RegistrationDate : POSIXct, format: NA NA NA NA ...
$ Event_Date : POSIXct, format: "2021-06-29" "2021-08-04" "2021-07-30" "2021-07-28" ...
$ InterviewDate : Date, format: "2021-07-14" "2021-08-31" "2021-08-14" "2021-08-13" ...
$ ModelCode : logi NA NA NA NA NA NA ...
$ Data_Type_ID : Factor w/ 4 levels "xxx","yyy",..: 2 2 2 2 2 2 2 2 2 2 ...
$ VehicleTypeID : int 1 NA 1 1 2 1 2 1 1 1 ...
$ URN : chr "21GB017097" "21GB00110440" "21GB00109687" "21GB0326133" ...
$ QA1 : int 10 10 10 10 10 10 10 10 10 10 ...
$ QA31 : int 10 10 10 10 10 10 10 10 10 10 ...
$ QN3a : chr "Everything explained well, from start to finish was a good experience " NA NA "Helpful advised on model and wating times " ...
$ QN5a : chr NA NA NA "Time it took to hand over " ...
$ QN5b : chr NA NA NA NA ...
$ QN3b : chr NA NA NA NA ...
$ QF70 : int 10 10 10 10 8 10 10 10 10 10 ...
$ Q11 : Factor w/ 4 levels "Yes, it was offered spontaneously",..: 1 4 2 1 4 1 4 1 1 1 ...
$ QF71 : chr NA NA NA NA ...
and I can see this error:
Error: 'nchar()' requires a character vector
What can I change in my code? Can you help?