Name | Gender | Designation | SSN | Age |
Wlliam Johnson | M | Officer | 222-22-1111 | 25 |
Mike Smith | M | Intern | 333-33-1111 | 22 |
Tom Walker | M | Accountant | 200-20-2000 | 23 |
Jared Smith | M | CEO | 211-11-2111 | 20 |
Walker Johnson | M | CFO | 300-00-0122 | 21 |
William Smith | M | Supervisor | 123-12-1234 | 28 |
Haley Smith | F | Asst. Supervisor | 234-23-2345 | 29 |
Sheley Homes | F | Safety Mngr | 555-55-5656 | 22 |
Kate Winslate | F | Receptionist | 258-25-8888 | 24 |
Jack Dawson | M | Operator 1 | 235-21-0000 | 27 |
Beth Kenyatta | F | Operator 2 | 411-33-2546 | 30 |
Simba Wetu | M | Inspector | 365-25-1234 | 23 |
Jane Sams | F | Driver | 100-45-2150 | 34 |
Joshua Knowles | M | Shipping Clerk | 300-16-7140 | 31 |
Martha Stewart | F | Shipping Mngr | 100-15-1324 | 25 |
Ashley Thompson | F | Janator | 300-56-4123 | 26 |
Asha Williams | F | Trainer | 201-23-1235 | 30 |
Jared Walker | M | IT Manager | 450-47-2354 | 25 |
Taylor Homes | F | R&D Intern | 532-11-2563 | 33 |
Mike Weber | M | Analyst | 325-00-1254 | 31 |
Copy and Paste data to excel and using RStudio help with the following
2. Output all the employee genders.
3. Output all the details of employees 12:20
4. Output the summary of the data frame.
5. Add a new employee row to the data frame.
6. Output all the details of the employees whose designation belongs to a category you prefer. For example, clerk.
7. Output all the details of the employees whose age is greater than a particular number. For example, age>20.
8. Write the data frame to a csv file.
9. Read this csv file into R with and without default headers.
10. Change the SSN number of an employee to a new number you like. For example, if it was 300-16-7140 initially, change it to 200-45-2150.
Firstly reading csv into dataframe using read.csv() function
data<-read.csv(file="C:/Users/keerthi
raja/Desktop/Book1.csv")
new<-data.frame(data)
new
the initial output is:
2) simply to display all the genders use $symbol to select particula column from the data frame
new$Gender
output:
3) now to display 12:20 all employees data use indexing of data frames
new[12:20,] //which means select 12:20 rows with all columns
output:
4)summary() function will give following results:
output:
5) we add a new row using rbind() function
newemployee<-data.frame(Name="Jonathan",Gender="M",Designation="CEO",SSN="100-101-224",Age=22)
rbind(new,newemployee)
output:
6) to subset a dataframe using a specific condition we use subset() function
Ceo<-subset(new,Designation ==
"CEO")
print(Ceo)
output:
7) newdata<-subset(new, age > 20)
newdata
8) For writing we have write.csv() function
write.csv(new,"myname.csv")
Name Gender Designation SSN Age Wlliam Johnson M Officer 222-22-1111 25 Mike Smith M Intern 333-33-1111...