4. Suppose we interview 5 individuals who are registering to vote in the 2016 US Presidential election, and learn the following about them in terms of their Age (years) and Income (annual): voter 1 is 25 years of age and reports an annual income of $24,000; voter 2 is 37 years with an income of $42,000; voter 3 is 45 years with an income of $39,000; voter 4 is 57 years with income of $77,000; and voter 5 is 65 years with income $84,000. Use R to create a data frame consisting of these 5 individuals and 2 variables. Name the variables Age and Income and the data frame E1_ 2.
Answer:
#Comment1. create the variable for Age
age <- c(25, 37, 45, 57, 65)
#Comment2. create the variable for Income
income <- c(24000, 42000, 39000, 77000, 84000)
#Comment3. create the data frame E1_2
E1_2 <- data.frame(Age = age, Income = income)
#Comment4. report the contents of the data frame E1_2
E1_2
## Age Income
## 1 25 24000
## 2 37 42000
## 3 45 39000
## 4 57 77000
## 5 65 84000