Recode variables in R

In data analysis it is often needed to set new values to a variable based on one or several conditions, and these kinds of operations are called recode variables. The most frequently applied recoding variables in R may be the setting some values to missing values (NA), and recoding a continuous to the values of a categorical variable.