Question: For the problems which involve writing R code, you will need to submit the R markdown file and outputted pdf to Canvas. Be sure to
For the problems which involve writing R code, you will need to submit the R markdown file and outputted pdf to Canvas. Be sure to include your name in the header of your RMD program.
Consider the MAJOR data frame.
a Create a for loop that calculate the percentage employed out of the total. The output should be a saved as a new column in the MAJOR data frame as employforloop Print the majors only for the highest employment rates.
b Create a for loop that goes through each major and labels the major as "Highly Popular", "Popular", "Less Popular" based on the Total column. Save the output in a variable called popular Print all majors with the label "Less Popular". The cut offs for each label are as follows:
i "Highly Popular"
ii "Popular"
iii. "Less Popular"
Write a for loop that goes through a vector of values from to by s and squares each value.
a Print the created vector of squares.
Write a for loop that prints out the square roots of a vector of values. Create a vector called NUMS to test the for loop containing the values and
Consider the dt data fame from the dspsy package. This can be loaded into R with the following code dt dspsy::dt
a Create two new columns. The first column should be date of birth in a year, month, day format. The second column is datetime of birth. This format should be year, month, day, hour, minute, second. Name the columns dob and tob respectively.
b Add two columns that contain the day of the week by name ie Monday, Tuesday, Wednesday, etc. and the name of the month January February, March, etc. of the date of birth.
c Using the sysdate function, add a column called todaydate Each row should contain the same date. This date should be in a ymd format.
d Using interval calculate the age of each person as a new column called age Round down to the nearest integer.
e Sort the data frame by name ZA Print the data frame.
Consider the FAME data frame.
a Convert the DOB and DOD variables into a POSIXct datatype in a month, day, year format.
b Using Summary, check the variables. You should see some missing data. Assessing the data further, do these NA's make sense? If not, what should you do to correct them. Write your answer and explain as a comment below the summary function.
c Remove all individuals who are missing the DOD variable. Save this data set into a new object and assign an appropriate name.
d Using the new object created in part C calculate age at death. Print the individuals name who was the oldest when they died.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
