# Creating three atomic vectors
<- c(11, 9, 8, 10, 5)
age <- c("Raju", "Raj", "Raba", "Rahul", "Rimi")
name <- c("boy", "boy", "girl", "boy", "girl")
sex <- c(1, 2, 1, 1, 2)
loc
# Creating data frame
<- data.frame(age, name, gender=sex, loc)
df
# Convert categorical variables to factor
$gender <- factor(df$gender)
df$loc <- factor(df$loc, labels=c("Urban", "Rural"))
df
# Print df
df
age name gender loc
1 11 Raju boy Urban
2 9 Raj boy Rural
3 8 Raba girl Urban
4 10 Rahul boy Urban
5 5 Rimi girl Rural