Assignment 2
Create a file named sample_study.R
and write a comment containing your name, your SciNet user name and a short description of what this script is doing. For example:
# Name: Alexey Fedoseev
# SciNet username: alexey
# Description:
# script prints a list of patients born in a specific year
Add the following lines to this file:
years <- c(1993, 1999, 1993, 1995, 1991, 1991, 1996, 1991,
1997, 1998, 1999, 1994, 1997, 1997, 1992, 1998, 1994,
1996, 1999, 1992, 1995, 1994, 1991, 1998, 1998)
months <- c(9, 2, 1, 6, 1, 9, 9, 7, 2, 1, 10, 5, 2, 10,
12, 8, 1, 11, 2, 11, 2, 1, 4, 1, 3)
ci.types <- c(20, 22, 11, 15, 19, 15, 17, 24, 6, 19, 19,
15, 6, 2, 22, 21, 24, 4, 3, 2, 8, 24, 5, 19, 18)
volumes <- c(8, 6, 3, 7, 4, 5, 3, 6, 6, 7, 5, 3, 6, 4, 5,
3, 5, 4, 4, 5, 7, 4, 4, 6, 6)
students <- c("Bert", "Bert", "Bert", "Bert", "Bert",
"Frank_Richard", "Frank_Richard", "Frank_Richard", "Frank_Richard", "Frank_Richard",
"Lawrence", "Lawrence", "Lawrence", "Lawrence", "Lawrence",
"THOMAS", "THOMAS", "THOMAS", "THOMAS", "THOMAS",
"alexander", "alexander", "alexander", "alexander", "alexander")
Following the example in the class use the vectors years, months, ci.types, volumes
and students
to create a data frame named mystudy
.
Use the command colnames
to rename the columns of the data frame mystudy
into "Year.of.birth", "Month.of.birth", "CI.type", "Volume", and "Student" correspondingly.
Create a variable search.year
and assign it the value of 1991.
Part 1: Using the defined variable search.year
perform conditional slicing of the data frame mystudy
to find which patients were born in 1991. Assign the result to a variable born.in.year
and
display it on the screen.
In order to display the data frame use the command print
:
print(born.in.year)
Display the total number of patients born in 1991 using the command nrow
. This command calculates the number of rows in a dataframe.
Part 2: Provide a code showing how many individuals were born in the second quarter (i.e., between April 1st to June 30th) in the years after 1991.
Your final script sample_study.R
should display the following information when run in the terminal:
user@scinet assignment2 $ Rscript sample_study.R
Patients born in 1991
------------------------------------------------------------
Year.of.birth Month.of.birth CI.type Volume Student
5 1991 1 19 4 Bert
6 1991 9 15 5 Frank_Richard
8 1991 7 24 6 Frank_Richard
23 1991 4 5 4 alexander
------------------------------------------------------------
Total number of patients born in 1991 is 4
------------------------------------------------------------
There are 2 individuals born in the second quarter (i.e., between April 1st to June 30th) after 1991
Submit your script sample_study.R
.
Assignments will be graded on a 10 point basis.
Due date is September 28th, 2023 at 11:55 p.m., with 0.5 point penalty per day for late submission until the cut-off date of October 5th, 2023 at 9:00 a.m.