Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using R code in R Studio Q1 Read Employee.xlsx file and store all data in a data frame named employee. a. (6 pts) Find who

Using R code in R Studio Q1 Read Employee.xlsx file and store all data in a data frame named employee. a. (6 pts) Find who worked the most among Selina, Ahana, and Kailee. Print one of the following three outputs by comparing their number of years worked: Selina worked the most Ahana worked the most Kailee worked the most You should write an if statement for comparison b. Add new column to the data frame named "Over100K" and set it to "Yes" if the salary is greater than or equal to $100,000, "No" otherwise. c. By writing a loop, calculate the average salary of an employee who worked more than 10 years. In each iteration of the loop, check the number of years worked of one employee. If it is greater than 10, you can add his/her salary to the sum and increment a counter value. Finally, you can calculate the average salary at the end of the loop. You are not allowed to use vectorized operations or mean functions. Q2 a. Generate a random integer between -100 and 100. Print whether this number is positive odd, positive even, negative odd, negative even, or zero. The output of your code must be one of the following: Positive odd Positive even Negative odd Negative even Zero b. Generate 4 random positive integers a, b, c, and d in the range [1,20]. Then assuming [a,b] and [c,d] are two points, determine and print the direction of the point [c,d] with respect to the point [a,b]. Your code will print one of the following nine outputs: "SOUTH", "SOUTHWEST", "WEST", "NORTHWEST", "NORTH", "NORTHEAST", "EAST", "SOUTHEAST", and "IDENTICAL POINTS". You can find some examples below: a b c d [a,b] [c,d] DIRECTION 3 13 12 2 [3,13] [12,2] SOUTHEAST 7 3 16 12 [7,3] [16,12] NORTHEAST 14 3 9 3 [14,3] [9,3] WEST 12 13 12 13 [12,13] [12,13] IDENTICAL POINTS Q3 a. Compute the following sum using a loop: 1 2 + 3 4 + 999 1000 You are not allowed to use vectorized operations or built-in sum function. b. Generate a vector of 100 unique positive random integers from 1 to 1000. Then, using a loop (without using built-in functions or vectorized operations): Count how many of those numbers ends with 4 or 7. Compute the sum of the odd numbers between 300 and 500. c. Generate a random positive integer from 1 to 10000. Then using a loop (without using built-in functions or vectorized operations), print whether the given number is a perfect number or not. A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For instance, 6 has divisors .

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Complex Variables and Applications

Authors: James Brown, Ruel Churchill

8th edition

73051942, 978-0073051949

More Books

Students also viewed these Mathematics questions