I'm not sure how to fix this na_if() error.
Code I'm Trying to Run
change variable types and recode
educ.cleaned <- educ %>%
select(-...2) %>%
slice(1:280) %>%
rename(country = "Country", perc.in.school = "...3",
female.in.school = "...4", male.in.school = "...5") %>%
na_if("") %>%
mutate(perc.in.school = 100 - as.numeric(perc.in.school)) %>%
mutate(female.in.school = 100 - as.numeric(female.in.school)) %>%
mutate(male.in.school = 100 - as.numeric(male.in.school))
Output
Error in na_if()
:
! Can't convert y
to match type of x
<tbl_df>.
Run rlang::last_error()
to see where the error occurred.
rlang::last_error()
<error/vctrs_error_cast>
Error inna_if()
:
! Can't converty
to match type ofx
<tbl_df>.
Backtrace:
- ... %>% ...
- dplyr::na_if(., "..")
Runrlang::last_trace()
to see the full context.
rlang::last_trace()
<error/vctrs_error_cast>
Error inna_if()
:
! Can't converty
to match type ofx
<tbl_df>.
Backtrace:
▆
- ├─... %>% ...
- ├─dplyr::mutate(., male.in.school = 100 - as.numeric(male.in.school))
- ├─dplyr::mutate(., female.in.school = 100 - as.numeric(female.in.school))
- ├─dplyr::mutate(., perc.in.school = 100 - as.numeric(perc.in.school))
- ├─dplyr::na_if(., "..")
- │ └─vctrs::vec_cast(x = y, to = x, x_arg = "y", to_arg = "x")
- └─vctrs (local)
<fn>
() - └─vctrs::vec_default_cast(...)
-
├─base::withRestarts(...)
-
│ └─base (local) withOneRestart(expr, restarts[[1L]])
-
│ └─base (local) doWithOneRestart(return(expr), restart)
-
└─vctrs::stop_incompatible_cast(...)
-
└─vctrs::stop_incompatible_type(...)
-
└─vctrs:::stop_incompatible(...)
-
└─vctrs:::stop_vctrs(...)
-
└─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = vctrs_error_call(call))