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.
1. 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 `employ_forloop`. Print the majors only for the 10 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" >=300,000
ii. "Popular" =5,500-300,000
iii. "Less Popular" =<5,500
2. Write a for loop that goes through a vector of values from 1 to 20 by 2s and squares each value.
a. Print the created vector of squares.
3. 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 25,65,90,100,110,144, and 800.
4. Consider the `dt_10` data fame from the ds4psy package. (This can be loaded into R with the following code dt_10<- ds4psy::dt_10)
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 (i.e. Monday, Tuesday, Wednesday, etc.) and the name of the month (January, February, March, etc.) of the date of birth.
c. Using the sys.date() function, add a column called `today.date`. 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 Z-A. Print the data frame.
5. 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 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!