Question

How would you write code in R studio for: Step 2: In a new code chunk...

How would you write code in R studio for:

Step 2: In a new code chunk below the last, write code that will create a subset of the data containing just the name, height and weight columns for males that are no more than 48" tall (Southpark fitness data) or no more than 68" tall (your own lab 1 fitness data).

Step 3: Below the last code, write another command that will create a dataframe with just the name, time, sbp, dbp and xbp variables for females at least 9 years old (Southpark fitness data) or at least 19 years old (your own lab 1 fitness data).

Generic structure: newdataset <- subset(parentdataset, cases to retain, select=c(list of variables))

Some examples:

data.l.males <- subset(data.l, gender=="m") #Just the males.

data.l.a8 <- subset(data.l, age==8)   #Just the 8 year olds.

data.l.h48 <- subset(data.l, height >= 48) #Just the subjects at least 48" tall ( >= means "greater than or equal to")

data.l.a9m <- subset(data.l, age==9 & gender=="f") #Just the 9 year old females

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Assuming the South park fitness data is in variable "data.I".

Step 2:

# This line code will fetch only the specified column i.e name, height and weight

data.i.col <- subset(data.I, select = c("name","height","weight", "gender"))

# This line of code will extract data created from the above step

data.i.male <- subset(data.i.col, height > 48 & height < 68 & gender == "male"))

Step 3:

# This line code will fetch only the specified column whose gender is female and age is atleast 9 years.

data.i.col <- subset(data.I, select = c("name","time","sbp", "dbp", "xbp") & gender == "female" & age >= 9)

Add a comment
Know the answer?
Add Answer to:
How would you write code in R studio for: Step 2: In a new code chunk...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Paste the R code for each exercise along with the answers. If: Age <- c(22, 25,...

    Paste the R code for each exercise along with the answers. If: Age <- c(22, 25, 18, 20) Name <- c("James", "Mathew", "Olivia", "Stella") Gender <- c("M", "M", "F", "F")       then what is the R-code for getting the following output: ##   Age   Name Gender ## 1 22 James      M ## 2 25 Mathew      M a. DataFrame = data.frame(c(Age), c(Name), c(Gender)) subset(DataFrame, Gender == "M") b. DataFrame = data.frame(c(Age),c(Name),c(Gender)) subset(Gender=="M"), eval=FALSE c. DataFrame = data.frame(Age,Name,Gender) subset(DataFrame,Gender=="M") d. DataFrame = data.frame(c(Age,Name,Gender))...

  • + Run C Code IMPORTANT: • Run the following code cell to create the input file,...

    + Run C Code IMPORTANT: • Run the following code cell to create the input file, biostats.csv, which you will be using later. 74, In [ ]: N %%file biostats.csv Name, Sex, Age, Alex, M, 41, Bert, M, 42, Dave, M, 39, Elly, F, 30, Fran, F, 33, Jake, M, F, Luke, M, 34, F Myra, M, M, 38, Ruth, F, 28, 22 22 323 47 47, Height, Weight 170 200 167 70 115 143 139 280 98 75, 350...

  • An over-the-counter drug manufacturer wants to examine the effectiveness of a new drug in curing an illness most commonly found in older patients. Thirteen patients are given the new drug and 13 patie...

    An over-the-counter drug manufacturer wants to examine the effectiveness of a new drug in curing an illness most commonly found in older patients. Thirteen patients are given the new drug and 13 patients are given the old drug. To avoid bias in the experiment, they are not told which drug is given to them. To check how the effectiveness depends on the age of patients, the following data have been collected. To examine the differences between salaries of male and...

  • The body mass index (BMI) is a measure of relative weight based on height and weight....

    The body mass index (BMI) is a measure of relative weight based on height and weight. The body fat percentage (BFP) of a human or other living being is the total mass of fat divided by total body mass, multiplied by 100; body fat includes essential body fat and storage body fat. Essential body fat is necessary to maintain life and reproductive functions. Write a program that calculates and prints the BFP for multiple persons; the program allows user to...

  • Write in python code Project 11-1: Birthday Calculator Create a program that accepts a name and...

    Write in python code Project 11-1: Birthday Calculator Create a program that accepts a name and a birth date and displays the person's birthday the current day, the person's age, and the number of days until the person's next birthday Console Birthday Calculator Enter name: Joel Enter birthday (MM/DD/YY): 2/4/68 Birthday: Sunday, February 04, 1968 Today: Joel is 48 years old. Joel's birthday is in 73 days Tuesday, November 22, 2016 Continue? (y/n): y Enter name: Django Enter birthday (MM/DD/YY):...

  • Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and...

    Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and please add comments for the whole code. Include a class diagrams, and explain the approach you used for the project and how you implemented that, briefly in a few sentences. Please note the following: -Names chosen for classes, functions, and variables should effectively convey the purpose and meaning of the named entity. - Code duplication should be avoided by factoring out common code into...

  • Ecology questions for final exam (Practice). Just the answers for now are fine but will ask...

    Ecology questions for final exam (Practice). Just the answers for now are fine but will ask questions depending on the answer. THANK YOU. Covid-19 has made learning difficult. 16. Competition has a negative effect on the individual's fitness via its negative effect on survival, growth, fecundity a. True b. False 90-94 Age 25-29 Questions 17 - 21 are based on the graph to the right. This graph describes the age structure of a population 100+ 95-99 17. The fraction of...

  • Homework 4 Use the hand span data that we collected in class for homework Suppose you...

    Homework 4 Use the hand span data that we collected in class for homework Suppose you want to buy someone a pair of love, but you do not know their love size. Usually, we do have a pretty good idea of the person's height. Let' asume that the right hand span is a rood indicator of the love size. So let find the best predictor of right hand span be on the person's height. Once we can predict the right...

  • write by python code and screenshoot the python code for me. thanks The Problem: You are...

    write by python code and screenshoot the python code for me. thanks The Problem: You are to design a Calorie Intake Assistant tailored to the user’s personal characteristics. The assistant will initially ask the user for his/her gender, name, age in years, height in cm and weight in kg. Based on these, the assistant will calculate the recommended daily calorie intake (RDCI) using the Mifflin – St Jeor formula[1], which is also shown to the user: Mifflin – St Jeor...

  • using this code to complete. it python 3.#Display Program Purpose print("The program will show how much...

    using this code to complete. it python 3.#Display Program Purpose print("The program will show how much money you will make working a job that gives a inputted percentage increase each year") #Declaration and Initialization of Variables userName = "" #Variable to hold user's name currentYear = 0 #Variable to hold current year input birthYear = 0 #Variable to hold birth year input startingSalary = 0 #Variable to hold starting salary input retirementAge = 0 #Variable to hold retirement age input...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT