Question

In: Statistics and Probability

RSQLite (using R studio) 1. Make you have imported the database tables into your database (I've...

RSQLite (using R studio)

1. Make you have imported the database tables into your database (I've copied and pasted these at the bottom). Write and submit the following RSQLite queries.

2. Retrieve the names of all employees.

3. Retrieve the names of all distinct employee names.

4. Retrieve the names of all employees whose name begins with the letter ‘B’.

5. Retrieve the names and NI numbers (NI_NO) of all employees.

6. Retrieve details of employees who are over 31 years of age.

7. Retrieve details of employees who are between 31 years of age and 65 years of age.

8. Retrieve the average employee age, the age of the youngest employee and the age of the oldest employee.

9. Retrieve the names of all employees and the names of the departments in which they work.

10. Retrieve details of employees who share the phone extension 123.

EMPLOYEE.txt
EMP_N0,NI_NO,NAME,AGE,DEPT_NO
E1,123,SMITH,21,D1
E2,159,SMITH,31,D1
E3,5432,BROWN,65,D2
E5,7654,GREEN,52,D3

PRODUCT.txt
PROD_NO,NAME,COLOR
p1,PANTS,BLUE
p2,PANTS,KHAKI
p3,SOCKS,GREEN
p4,SOCKS,WHITE
p5,SHIRTS,WHITE

SALES ORDER LINE.txt
ORDER_NO,PROD_NO,QUANTITY
01,p1,10
02,p1,10
02,p4,20
09,p1,05
010,p1,05

INVOICES.txt
ORDER_NO,PROD_NO,QUANTITY,PRICE
01,p1,100,2.99
01,p2,20000,2.99
01,p6,20,14.98
02,p2,1000,14.98
02,p6,10000,14.98

SALES ORDER.txt
ORDER_NO,DATE,CUST_NO
01,11/11/17,C1
02,7/9/17,C3
09,8/16/17,C6
010,10/12/17/,C6

CUSTOMER.txt
CUST_NO,NAME,ADDRESS
C1,ALEX,State
C2,BOB,Hollister
C3,CAROL,Ocean
C6,JUAN,Phelps

DEPARTMENT.txt
DEPT_NO,NAME,MANAGER
D1,Accounts,E1
D2,Stores,E2
D3,Sales,null

Solutions

Expert Solution

R-code

> EMP_NO=c("E1","E2","E3","E5")
> EMP_NO
[1] "E1" "E2" "E3" "E5"
> NI_NO=c(123,159,5432,7654)
> NI_NO
[1] 123 159 5432 7654
> NAME=c("SMITH","SMITH","BROWN","GREEN")
> NAME
[1] "SMITH" "SMITH" "BROWN" "GREEN"
> AGE=c(21,31,65,52)
> AGE
[1] 21 31 65 52
> DEPT_NO=c("D1","D1","D2","D3")
> DEPT_NO
[1] "D1" "D1" "D2" "D3"

1. Make you have imported the database tables into your database

> D=data.frame(EMP_NO,NI_NO,NAME,AGE,DEPT_NO)
> D
EMP_NO NI_NO NAME AGE DEPT_NO
1 E1 123 SMITH 21 D1
2 E2 159 SMITH 31 D1
3 E3 5432 BROWN 65 D2
4 E5 7654 GREEN 52 D3

> data=as.matrix(data.frame(EMP_NO,NI_NO,NAME,AGE,DEPT_NO))
> data
EMP_NO NI_NO NAME AGE DEPT_NO
[1,] "E1" " 123" "SMITH" "21" "D1"
[2,] "E2" " 159" "SMITH" "31" "D1"
[3,] "E3" "5432" "BROWN" "65" "D2"
[4,] "E5" "7654" "GREEN" "52" "D3"

2. Retrieve the names of all employees.

> Names=data[,3]
> Names
[1] "SMITH" "SMITH" "BROWN" "GREEN"

3. Retrieve the names of all distinct employee names.

> dist.Names=Names[c(1,3,4)]
> dist.Names
[1] "SMITH" "BROWN" "GREEN"

4. Retrieve the names of all employees whose name begins with the letter ‘B’.

> B_Names=Names[3]
> B_Names
[1] "BROWN"

5. Retrieve the names and NI numbers (NI_NO) of all employees.

> d=data[,c(3,2)]
> d
NAME NI_NO
[1,] "SMITH" " 123"
[2,] "SMITH" " 159"
[3,] "BROWN" "5432"
[4,] "GREEN" "7654"

6. Retrieve details of employees who are over 31 years of age.

> det=data[3:4,]
> det
EMP_NO NI_NO NAME AGE DEPT_NO
[1,] "E3" "5432" "BROWN" "65" "D2"
[2,] "E5" "7654" "GREEN" "52" "D3"   

7. Retrieve details of employees who are between 31 years of age and 65 years of age.

> detail=data[2:4,]
> detail
EMP_NO NI_NO NAME AGE DEPT_NO
[1,] "E2" " 159" "SMITH" "31" "D1"
[2,] "E3" "5432" "BROWN" "65" "D2"
[3,] "E5" "7654" "GREEN" "52" "D3"

8. Retrieve the average employee age, the age of the youngest employee and the age of the oldest employee.

> Ave.age=mean(D[,4])
> Ave.age
[1] 42.25

> young_Employee=max(D[,4])
> young_Employee
[1] 65
> Old_Employee=min(D[,4])
> Old_Employee
[1] 21

9. Retrieve the names of all employees and the names of the departments in which they work.

> NandD=data[,c(3,5)]
> NandD
NAME DEPT_NO
[1,] "SMITH" "D1"
[2,] "SMITH" "D1"
[3,] "BROWN" "D2"
[4,] "GREEN" "D3"

10. Retrieve details of employees who share the phone extension 123.

> phone_ext=data[1,]
> phone_ext
EMP_NO NI_NO NAME AGE DEPT_NO
"E1" " 123" "SMITH" "21" "D1"

____________________________________________________________________________________________

R-code

EMP_NO=c("E1","E2","E3","E5")
EMP_NO
NI_NO=c(123,159,5432,7654)
NI_NO
NAME=c("SMITH","SMITH","BROWN","GREEN")
NAME
AGE=c(21,31,65,52)
AGE
DEPT_NO=c("D1","D1","D2","D3")
DEPT_NO
D=data.frame(EMP_NO,NI_NO,NAME,AGE,DEPT_NO)
D
data=as.matrix(data.frame(EMP_NO,NI_NO,NAME,AGE,DEPT_NO))
data
Names=data[,3]
Names
dist.Names=Names[c(1,3,4)]
dist.Names
B_Names=Names[3]
B_Names
d=data[,c(3,2)]
d
det=data[3:4,]
det
detail=data[2:4,]
detail
Ave.age=mean(D[,4])
Ave.age
young_Employee=max(D[,4])
young_Employee
Old_Employee=min(D[,4])
Old_Employee
NandD=data[,c(3,5)]
NandD
phone_ext=data[1,]
phone_ext


Related Solutions

R - STUDIO R PROGRAMMING STATISTICS Imagine that you and your friend have catched COVID-19 while...
R - STUDIO R PROGRAMMING STATISTICS Imagine that you and your friend have catched COVID-19 while jogging without social distancing. Your case is more severe than your friend’s at the beginning: there are 400 millions of coronavirus in you, and only 120 millions in your friend. However, your immune system is more effective. In your body the number coronavirus decrease by 20 percent each day (new = 0.8 × orginal), while in your friend it increases by 10 percent each...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based on your entities defining The attributes within each table The primary and foreign keys within each table *****Show your database tables, tables attributes, primary and foreign keys***** Do not forget to check the lesson slides and videos that show you how to convert an ER/EER into a database schema, and how to create a database and tables using MS SQL Server.
Can You please Answer the question using R studio and R cloud Telomeres are complexes of...
Can You please Answer the question using R studio and R cloud Telomeres are complexes of DNA and protein that cap chromosomal ends. They consist of the same short DNA sequence TTAGGG repeated over and over again. They tend to shorted with cell divisions and with advancing cellular age, which will lead to chromosome instability or apoptosis (programmed cell death). Eukaryotic cells have the ability to reverse telomere shortening by expressing telomerase, an enzyme that extends the telomeres of chromosomes....
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...
Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient,...
Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient, fullName, biologicalMother, birthdate, address) doctor(idDr, fullName, specialization, consulRates) inpatient(idPatient, entryTime, outTime, idDr, idRoom). Please make entryTime as column that is going to be filled automatically when care record is being add room(idRoom, roomName, cost) fill the data above to each table Create sql query and relational algebra expressions for the query Please give me detailed answer so I could learn from it. Thank you...
Part 2: You will create five tables in your ColonialAdventureTours database. Please do not write your...
Part 2: You will create five tables in your ColonialAdventureTours database. Please do not write your own SQL Commands for this task, use data found in the following Colonial_create.txt file and copy and paste the commands into MySQL workbench. Then add Primary key, Foreign key, and not null constraints appropriately. Then run your codes. Note: Remember that since you enforced referential integrity (foreign key constraints) that you must create the "primary" tables before you can create the "related" tables in...
I want this to be solved using R studio or R software, please. Here is the...
I want this to be solved using R studio or R software, please. Here is the example: The data in stat4_prob5 present the performance of a chemical process as a function of sever controllable process variables. (a) Fit a multiple regression modelrelating CO2product (y) to total solvent (x1) and hydrogen consumption (x2) and report the fitted regression line. (b) Find a point estimatefor the variance term σ2. (c) Construct the ANOVA tableand test for the significance of the regression using...
Using R-Studio please answer the following questions and show your code. 1. Julie buys a take-out...
Using R-Studio please answer the following questions and show your code. 1. Julie buys a take-out coffee from one of two coffee shops on a random basis: Ultimo Coffee and Joe’s Place. This month, she measured the temperature of each cup immediately after purchase, using a cooking thermometer. Sample data is shown below, temperatures are in Fahrenheit. ultimo =  c(171,161,169,179, 171,166,169,178,171, 165,172,172) joes = c(168,165,172, 151,162,158,157,160, 158,160,158,164) State the null and alternative hypothesis in your own words. What type of statistical...
Solve following using Program R studio. Please show code and results. Thank you. 1. Assume that...
Solve following using Program R studio. Please show code and results. Thank you. 1. Assume that ? is a random variable follows binomial probability distribution with parameters 15 and 0.25.   a. Simulate 100 binomial pseudorandom numbers from the given distribution (using set.seed(200)) and assign them to vector called binran. b. Calculate ?(? < 8) using cumulative probability function. c. Calculate ?(? = 8) using probability distribution function. d. Calculate the average of simulated data and compare it with the corresponding...
Need To Do this in R Studio...Here are the Instruction steps: 1. Using the 1:n construct,...
Need To Do this in R Studio...Here are the Instruction steps: 1. Using the 1:n construct, create the sequence 4,8,12, ..., 48. 2. Similarly, create the sequence 0,5,10,15, ..., 100. 3. Using a for() loop and the print() function, print the values 2,3,4,..., 7. 4. Using a for() loop and the print() function, print the values 8,11,14, ..., 26. 5. Create a vector with a length of 10. Then, using a for() loop, assign the values 3,6,9, ..., 30. to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT