Trouble recoding variable

Hi, newbie here, so I'm working on recoding my dataset.

I've successfully recoded all of the items that similar to this

PD_dataset_clean$LPSF_80 <- recode(PD_dataset_clean$LPSF_80,

"'Totally False, not at all True' = 1;

'Slightly True' = 2;

'Mainly True' = 3;

'Very True' = 4")

however, when i run this:

PD_dataset_clean$ders_5 <- recode(PD_dataset_clean$ders_5,

"'Almost never (0-10%)' = 1;

'Sometimes (11-35%)' = 2;

'About half the time (36-65%)' = 3;

'Most of the time (66-90%)' = 4;

'Almost always (91-100%)' = 5")

It successfully runs but it doesn't code in my dataset.

I also tried:

PD_dataset_clean$ders_3 <- recode(PD_dataset_clean$ders_3,

'Almost never (0-10%)' ~ 1,

'Sometimes (11-35%)' ~ 2,

'About half the time (36-65%)' ~ 3,

'Most of the time (66-90%)' ~ 4,

'Almost always (91-100%)' ~ 5)

and this error comes up: Error in if (grepl(paste0("[", separator, interval, "]"), to.value)) stop("to.value may not contain ", :

the condition has length > 1

i also tried:

PD_dataset_clean$ders_5 <- (recode(PD_dataset_clean$ders_5,

'Almost never (0-10%)'= 1,

'Sometimes (11-35%)'= 2,

'About half the time (36-65%)'= 3,

'Most of the time (66-90%)'= 4,

'Almost always (91-100%)'= 5)

this error comes up:

Error in recode(PD_dataset_clean$ders_5, Almost never (0-10%) = 1, :

unused arguments (Almost never (0-10%) = 1, Sometimes (11-35%) = 2, About half the time (36-65%) = 3, Most of the time (66-90%) = 4, Almost always (91-100%) = 5)

if i replace the commas with semicolons it says unexpected ";"

I'm not sure why everything else is coding except my "DERS" variables. Please let me know some other ways to recode or what's going wrong here. Thanks!

recode() is not a base R function, can you clarify what package comes from? the syntax varies depending on the package.

Ideally, can you please provide a proper REPRoducible EXample (reprex) illustrating your issue?

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.