I think this might work:
library(tidyverse)
dataie <- dataselected %>%
mutate(
ridageyr = case_when(
ridageyr < 18 ~ NA_integer_,
TRUE ~ as.numeric()
))
Edit: Submitting your question as a reproducible example would help others better answer your question. Welcome to the RStudio Community!