Question: In this question, we will practice how to subset a data frame in R . Below is the code for creating a data frame representing

In this question, we will practice how to subset a data frame in R. Below is
the code for creating a data frame representing data from a psychological study. Copy
and paste the code into your R studio editor and run the code. Answer the following
questions. Attach your code.
psych_study <- data.frame(
ID =1:10,
Age = c(22,34,29,40,25,30,38,28,33,41),
Gender = c("Male", "Female", "Non-Binary", "Female", "Male",
"Other", "Male", "Non-Binary", "Female", "Other"),
Ethnicity = c("Asian", "Black", "White", "Hispanic", "White",
"Asian", "Hispanic", "Black", "Other", "White"),
Anxiety_Score = c(3,7,5,2,6,4,8,3,7,1),
Happiness_Score = c(5,6,4,7,5,6,2,8,3,9)
)
(a) How to subset the column Ethnicity in three different ways?
(b) How to subset the columns Gender and Ethnicity in two different ways?
(c) How to subset the data (of all columns) for the first five participants?
(d) How to subset the Ethnicity and Gender for the first three participants?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!