This is my code:*
data %>%
mutate(r_stemster_3 = recode(stemster_3,
`1` = 7,
`2` = 6,
`3` = 5,
`4` = 4,
`5` = 3,
`6` = 2,
`7` = 1))
This is the error message:
Error in `mutate()`:
ℹ In argument: `r_stemster_3 = recode(...)`.
Caused by error in `recode()`:
! unused arguments (`1` = 7, `2` = 6, `3` = 5, `4` = 4, `5` = 3, `6` = 2, `7` = 1)
Backtrace:
1. data %>% ...
3. dplyr:::mutate.data.frame(...)
4. dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
6. dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
7. mask$eval_all_mutate(quo)
8. dplyr (local) eval()
Error in mutate(., r_stemster_3 = recode(stemster_3, `1` = 7, `2` = 6, :
Caused by error in `recode()`:
! unused arguments (`1` = 7, `2` = 6, `3` = 5, `4` = 4, `5` = 3, `6` = 2, `7` = 1)
I can't figure out what was wrong with my code. Please help fix the code!
I tried variations of the code such as removing the backticks or using single/double quotes instead of backticks. None of them worked.
Also data$stemster_3 is numeric and I want the reverse coded variable to be numeric too.
There are many ways to deal with reverse coding in R. Here are some:
note.
reverseitems <- c(-1, 1, 1)is here to indicateV1in the dataset. In this case, only the values in the first column will be reverse-coded.note. In this way, new variables will be added to the dataset (
sampledf).apply()functionnote. By using
c(1, 2, 3)you can specify the variables (eg. all variables). After having new dataset, you can merge the specific variables of the old and new datasets (data.frame()function).