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.

How to create factor variables in R programming

Categorical variables, including nominal and ordinal variables in R programming language are called factor variables. For example, gender(male/female) is nominal, and survey results (excellent, good, normal, bad) have ordinal values. Categorical variables are useful because many data analysis operations are related to values in different categories, such as contingency tables between two categorical variables for independence analysis, hypothesis testing of homogeneity of variances, just name a few.