Question

In: Computer Science

Write R commands for below queries, assume the data is in file named input.csv. Also explain...

  1. Write R commands for below queries, assume the data is in file named input.csv.

Also explain your answer

id

name

salary

start_date

dept

1

Rick

623.3

1/01/2012

IT

2

Dan

515.2

23/09/2013

Operations

3

Michelle

611

15/11/2014

IT

4

Ryan

729

11/05/2014

HR

5

Gary

843.25

27/03/2015

Finance

6

Nina

578

21/05/2013

IT

7

Simon

632.8

30/07/2013

Operations

8

Guru

722.5

17/06/2014

Finance

  1. Open the file and Get the max salary from data frame
  2. Get the detail of person having max salary
  3. Get all the people working in IT department   
  4. Get the persons in IT department whose salary is greater than 600           
  1. Write down the output of the following R commands. If not data is provided you can use any example data. Explain what does the command do?
  1. category <- 'A'   

price <- 10

if (category =='A'){

    cat('A vat rate of 8% is applied.','The total price is',price *1.08)

} else{

      cat('A vat rate of 10% is applied.','The total price is',price *1.10)

}

  1. a = c(5,7,2,9)   

ifelse(a %% 2 == 0,"even","odd")

Solutions

Expert Solution

STEP - BY - STEP PROCESS

(1.) Creating Dataframe, you can use by reading your input.csv

idname <- c('Rick', 'Dan', 'Michelle', 'Ryan', 'Gary', 'Nina', 'Simon', 'Guru')
salary <- as.numeric(c(623.3, 515.2, 611, 729, 843.25, 578, 632.8, 722.5))
start_date <- as.Date(c("1/01/2012", "23/09/2019", "15/11/2014", "11/05/2014",
                    "27/03/2013", "21/05/2013", "30/07/2013", "17/06/2014"))
dept <- c("IT", "Operations", "IT", "HR", "Finance", "IT", "Operations", "Finance")
df <- data.frame(idname, salary, start_date, dept)
df

Output:

(2.) Find Maximum Salary

max(df$salary)

Output:

(3.) Find details of person having maximum salary

df[df$salary == max(df$salary),]

Output:

(4.) Find all employee working at "IT" branch

df[df$dept == "IT",]

Output:

(5.) Find all employee working at "IT" branch and salary is greater than 600

df[(df$dept == "IT" & df$salary > 600),]

Output:

R - Commands

(1.)

category <- 'A'   
price <- 10

if (category == 'A'){
    cat('A vat rate of 8% is applied.','The total price is',price *1.08)
} else{
      cat('A vat rate of 10% is applied.','The total price is',price *1.10)
}

Output: It checks whehter catergory is 'A' or not. If it is 'A' then price will be multiplied by 1.08, if not then multiplied by 1.10

(2.)

a = c(5,7,2,9)   
ifelse(a %% 2 == 0,"even","odd")

Output: It checks and determines which number is even or odd in the given vector 'a'.

NOTE: Please use R-Studio for better understanding.

Thumbs Up Please !!!


Related Solutions

ASSIGNMENT: Enter the hypothetical data below in SPSS to use for the assignment.  The SPSS commands: 'file',...
ASSIGNMENT: Enter the hypothetical data below in SPSS to use for the assignment.  The SPSS commands: 'file', 'new', 'data' will create a spreadsheet in which to enter the data below (manually). Case Control Treatment 1                              5                              6 2                              4                              7 3                              5                              5              4                              4                              6 5                              5                              5 6                              6                              6 7                              5                              5 8                              4                              6 9                              5                              5 10                           5                              10 In this experiment, all participants rated the credibility of fake news stories on a scale of 1...
Write a program that creates an output file named rand_nums.txt. Open the file and write 100...
Write a program that creates an output file named rand_nums.txt. Open the file and write 100 random integers between -50 and +50 (inclusive) to the file. Be sure to handle any file IO exceptions. Remember to close the file. Write a program that opens rand_nums.txt for input. Create two output files pos.txt and neg.txt. Read through the input file, one line at a time, converting each line into an integer (no exception handling, yet). If the number is positive, write...
Write scores of 20 students on a quiz to a file. The file should be named...
Write scores of 20 students on a quiz to a file. The file should be named scores.txt. The scores should be random numbers between 0-10. Next, read the scores from scores.txt and double them and print the scores to screen. c++
Find the data for the problem in the first worksheet named LightbulbLife of the data file....
Find the data for the problem in the first worksheet named LightbulbLife of the data file. It gives the data on the lifetime in hours of a sample of 100 lightbulbs. The company manufacturing these bulbs wants to know whether it can claim that its lightbulbs typically last more than 1000 burning hours. So it did a study. Identify the null and the alternate hypotheses for this study. Can this lightbulb manufacturer claim at a significance level of 5% that...
USING R STUDIO- Write the r commands for the following. 1. Non-Linear Models 1.1 Load the...
USING R STUDIO- Write the r commands for the following. 1. Non-Linear Models 1.1 Load the {ISLR} and {GGally} libraries. Load and attach the College{ISLR} data set. [For you only]: Open the College data set and its help file and familiarize yourself with the data set and its fields. 1.2 Inspect the data with the ggpairs(){GGally} function, but do not run the ggpairs plots on all variables because it will take a very long time. Only include these variables in...
Write a Matlab script-file probl1.m to execute the requested commands (as much as possible) in the...
Write a Matlab script-file probl1.m to execute the requested commands (as much as possible) in the exercises below. Increase N a number of times according to N = 4, 8, 16, 32, 64, 128, . . . (1) Determine for each N the (exact) error. (2) Determine for N ≥ 16 also the convergence ratio q(h/2). This script should be based on a function-file trap.m (trapezoidal integration) as follows: function [totarea] = trap(N) format long; a = 0; b =...
In Python: Assume a file containing a series of integers is named numbers.txt and exists on...
In Python: Assume a file containing a series of integers is named numbers.txt and exists on the computer's Disk. Write a program that reads al the numbers stored in the file and calculates their total. - create your own text file called numbers.txt and put in a set of 20 numbers (each number should be between 1 and 100). - Each number should be on its own line. - do not assume that the file will always have 20 numbers...
demonstrate how to write a file named "hcsi 112.txt" while handling exceptions, the sentence given below...
demonstrate how to write a file named "hcsi 112.txt" while handling exceptions, the sentence given below into separate lines(i.e. each sentence begins from where the comma starts) "how are you today?, my name is Python, am easy to use, simple to write, and object oriented". Also show how to read the lines and store into a list.
This question requires using Rstudio. This is following commands to install and import data into R:...
This question requires using Rstudio. This is following commands to install and import data into R: > install.packages("ISLR") > library(ISLR) > data(Wage) The required data installed and imported, now this is description of the data: This dataset contains economic and demographic data for 3000 individuals living in the mid-Atlantic region. For each of the 3000 individuals, the following 11 variables are recorded: year: Year that wage information was recorded age: Age of worker maritl: A factor with levels 1. Never...
This question requires using Rstudio. This is following commands to install and import data into R:...
This question requires using Rstudio. This is following commands to install and import data into R: > install.packages("ISLR") > library(ISLR) > data(Wage) The required data installed and imported, now this is description of the data: This dataset contains economic and demographic data for 3000 individuals living in the mid-Atlantic region. For each of the 3000 individuals, the following 11 variables are recorded: year: Year that wage information was recorded age: Age of worker maritl: A factor with levels 1. Never...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT