In: Computer Science
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 |
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)
}
ifelse(a %% 2 == 0,"even","odd")
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 !!!