0% found this document useful (0 votes)
65 views10 pages

R Working Directory Management

The document contains instructions and output for an assignment on introduction to R. It asks the student to perform tasks like creating folders and subfolders, checking and changing the working directory, creating and manipulating vectors and matrices. It also asks to create a dataframe with employee data and perform operations on it like extracting rows and columns. The output shows the code and results for each task.

Uploaded by

Jidnesh madhavi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views10 pages

R Working Directory Management

The document contains instructions and output for an assignment on introduction to R. It asks the student to perform tasks like creating folders and subfolders, checking and changing the working directory, creating and manipulating vectors and matrices. It also asks to create a dataframe with employee data and perform operations on it like extracting rows and columns. The output shows the code and results for each task.

Uploaded by

Jidnesh madhavi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SIES College of Management Studies FYMCA (Revised), Sem I,

Roll No: 045

Assignment No. 1
 
MCA Batch 2022-24 
Subject : Advance Database Management System 
Assignment No. 1 
 
Introduction to R

Q1. Perform the following 


1. Create a folder on your computer for this course. Create a sub folder called
“Practicals”. Create another sub folder called “01_R_Introduction”. 
2. Get the current working directory using the getwd() function 
3. Set the working directory to the folder you created for this practical using
the setwd() function 
4. Check to make sure you have indeed changed the working directory. 
5. List all the files in the current working directory using [Link](). 
6. List the different ways of finding the help and example for the commands. 

OUTPUT

> [Link]("MCA22") 
> setwd("E:/Users/mca22_045/Documents/MCA22") 
> [Link]("Practicals") 
> setwd("E:/Users/mca22_045/Documents/MCA22/Practicals") 
> [Link]("01_R_Introduction") 

> getwd() 
[1] "E:/Users/mca22_045/Documents/MCA22/Practicals" 

> setwd("E:/Users/mca22_045/Documents/MCA22/Practicals/01_R_Introduction") 

> getwd() 
[1] "E:/Users/mca22_045/Documents/MCA22/Practicals/01_R_Introduction" 

> [Link]() 
character(0) 
> setwd("E:/Users/mca22_045/Documents/MCA22/Practicals") 
> getwd() 
[1] "E:/Users/mca22_045/Documents/MCA22/Practicals" 
> [Link]() 
[1] "01_R_Introduction" 

> help("[Link]") 
> help() 
 
 

Subject: MCAL13 Advanced Database Management System Academic Year First


Half 2022_23
Batch:2022_24
SIES College of Management Studies FYMCA (Revised), Sem I,
Roll No: 045

Assignment No. 1

Q2. Perform the following 

1. Create & assign some value to a variable “Z” 


2. Check the class and the type of variable “Z” 
3. Print the value of variable “Z” 
4. Assign the numbers from 1 to 10 to a variable “x”. Find the inverse tangent of the
reciprocal of x and assign it to a variable “y”.  Now calculate the reciprocal of the tangent
of y and assign it to a variable “z”.  Print the values of x, y and z 
5. Compare the variables x and z using ==, identical and [Link]. Find the result by
setting the tolerance value to 0 in [Link]. Print the results of the same. 
6. Check the class and type of special variables Inf, NaN, NA and “” 

OUTPUT

> z = 2 

> class(z) 
[1] "numeric"
 
> print(z) 
[1] 2 
 
 > x=1:10
> atan(x)
[1] 0.7853982 1.1071487 1.2490458 1.3258177 1.3734008 1.4056476
[7] 1.4288993 1.4464413 1.4601391 1.4711277
> y=atan(x)
> z=1/tan(y)
>z
[1] 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667
[7] 0.1428571 0.1250000 0.1111111 0.1000000
>y
[1] 0.7853982 1.1071487 1.2490458 1.3258177 1.3734008 1.4056476
[7] 1.4288993 1.4464413 1.4601391 1.4711277
>x
[1] 1 2 3 4 5 6 7 8 9 10

> x==y
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
> x==z
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 
> identical(x,z)
[1] FALSE
> identical(z,y)
[1] FALSE
Subject: MCAL13 Advanced Database Management System Academic Year First
Half 2022_23
Batch:2022_24
SIES College of Management Studies FYMCA (Revised), Sem I,
Roll No: 045

Assignment No. 1

> [Link](y,x)
[1] "Mean relative difference: 3.213569"

> class(Inf)
[1] "numeric"
> class(NaN)
[1] "numeric"
> class(NA)
[1] "logical"
> class("")
[1] "character"
>typeof(NaN)
[1] "double"
>typeof(Inf)
[1] "double"
>typeof(NA)
[1] "logical"
>typeof("")
[1] "character"

Q3. Perform the following 


1. Create two vectors “Vect_Y” and “Vect_Z” having numeric values with same length. 
2. Display the length of “Vect_Z” 
3. Multiply the vector “Vect_Z” by 3. 
4. Add the two vectors “Vect_Y” and “Vect_Z” 
5. Apply cbind and rbind functions on the two vectors. 
6. Create a vector “animals” by labeling with fruit names with values. Display the names
of the vector “animals”.  Access the value of the vector by its names. 

OUTPUT

> Vect_y = c(1,2,3,4,5) 


> Vect_z = c(5,6,7,8,9)
 
> length(Vect_z) 
[1] 5 

> M = Vect_z * 3 
> M 
[1] 15 18 21 24 27 

> A = Vect_y + Vect_z 


> A 
[1]  6  8 10 12 14 
Subject: MCAL13 Advanced Database Management System Academic Year First
Half 2022_23
Batch:2022_24
SIES College of Management Studies FYMCA (Revised), Sem I,
Roll No: 045

Assignment No. 1

> cbind(Vect_y, Vect_z) 


     Vect_y Vect_z 
[1,]      1      5 
[2,]      2      6 
[3,]      3      7 
[4,]      4      8 
[5,]      5      9 
> rbind(Vect_y, Vect_z) 
       [,1] [,2] [,3] [,4] [,5] 
Vect_y    1    2    3    4    5 
Vect_z    5    6    7    8    9 

> animals = c("Mango" = 1, "Banana" = 2, "Grapes" = 3) 


> animals 
 Mango Banana Grapes  
     1      2      3  
> animals["Mango"] 
Mango  
    1  
> animals["Grapes"] 
Grapes  
     3 
 
 

Q4. Create the following vectors in R. 


a = (5, 10, 15, 20, ..., 160) 
b = (87, 86, 85, ..., 56) 
Use vector arithmetic to multiply these vectors and call the result d.  Select subsets of d to
identify the following. 
a. What are the 19th, 20th, and 21st elements of d? 
b. What are all of the elements of d which are less than 2000? 
c. How many elements of d are greater than 6000? 
 

OUTPUT

> a=c(seq(5,160, by=5)) 


> a 
[1]   5  10  15  20  25  30  35  40  45  50  55  60  65  70  75  80  85  90  95 100 
[21] 105 110 115 120 125 130 135 140 145 150 155 160
 
> b=c(87:56) 
> b 
[1] 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 
[27] 61 60 59 58 57 56 

Subject: MCAL13 Advanced Database Management System Academic Year First


Half 2022_23
Batch:2022_24
SIES College of Management Studies FYMCA (Revised), Sem I,
Roll No: 045

Assignment No. 1
> d=c(a*b) 
> d 
[1]  435  860 1275 1680 2075 2460 2835 3200 3555 3900 4235 4560 4875 5180 5475 5760 
[17] 6035 6300 6555 6800 7035 7260 7475 7680 7875 8060 8235 8400 8555 8700 8835
8960 
> d[19] 
[1] 6555 
> d[20] 
[1] 6800 
> d[21] 
[1] 7035

> d[d<2000]
[1] 435 860 1275 1680

> d[d>6000]
[1] 6035 6300 6555 6800 7035 7260 7475 7680 7875 8060 8235 8400 8555 8700
[15] 8835 8960

 
 

[Link]
Following operations:

A as

2 7 7
5 9 6
7 12 10

And B as
12 10 67
14 16 10
2 13 12

a) Multiply A by 5
b) Display the dimension of matrices
c) Create an identity matrix of order 3 by 3 and store it in C.
d) Addition of two matrices (A and C)
e) Multiplication of two matrices (A and B)
f) Transpose of matrix B
g) Determinant of matrix A
 

Subject: MCAL13 Advanced Database Management System Academic Year First


Half 2022_23
Batch:2022_24
SIES College of Management Studies FYMCA (Revised), Sem I,
Roll No: 045

Assignment No. 1
OUTPUT

> A = matrix(c(2,7,7,5,9,6,7,12,10),nrow = 3,ncol=3,byrow=TRUE)


>A
[,1] [,2] [,3]
[1,] 2 7 7
[2,] 5 9 6
[3,] 7 12 10
> B = matrix(c(12,10,67,14,16,10,2,13,12),nrow =3,ncol=3, byrow=TRUE)
>B
[,1] [,2] [,3]
[1,] 12 10 67
[2,] 14 16 10
[3,] 2 13 12
> SA=A*5
> SA
[,1] [,2] [,3]
[1,] 10 35 35
[2,] 25 45 30
[3,] 35 60 50
> dim(A)
[1] 3 3
> dim(B)
[1] 3 3
> C = diag(x=3)
>C
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 1 0
[3,] 0 0 1
> SAB = A*B
> SAB
[,1] [,2] [,3]
[1,] 24 70 469
[2,] 70 144 60
[3,] 14 156 120
> SAC=A+C
> SAC
[,1] [,2] [,3]
[1,] 3 7 7
[2,] 5 10 6
[3,] 7 12 11
> ATRAN=t(B)
> ATRAN
[,1] [,2] [,3]
[1,] 12 14 2
[2,] 10 16 13
[3,] 67 10 12
> det(A)
[1] -41
Subject: MCAL13 Advanced Database Management System Academic Year First
Half 2022_23
Batch:2022_24
SIES College of Management Studies FYMCA (Revised), Sem I,
Roll No: 045

Assignment No. 1

Q6. Perform the following: 


a. Create a dataframe employee with four variables empid,empname,salary &
start_date. 
b. Display the data of employee 
c. Display the empname and salary column of employee 
d. Extract first two rows 
e. Extract 1st & 3rd row with 2nd & 3rd column.

OUTPUT

> empid=c(45:50)
> empname=c("Tejas", "Umang", "Jidnesh", "Rutik", "Advait", "Shreyas")
> empsalary=c(74000,78000,65000,86000,78500,69450)
> empstart_date=[Link](c("2023-08-25", "2023-08-24", "2023-07-29", "2023-08-01",
"2023-07-21", "2023-08-01"))
> companydocs=[Link](empid,empname,empsalary,empstart_date)

> companydocs
empid empname empsalary empstart_date
1 45 Tejas 74000 2023-08-25
2 46 Umang 78000 2023-08-24
3 47 Jidnesh 65000 2023-07-29
4 48 Rutik 86000 2023-08-01
5 49 Advait 78500 2023-07-21
6 50 Shreyas 69450 2023-08-01

> name=companydocs$empname
> name
[1] "Tejas" "Umang" "Jidnesh" "Rutik" "Advait" "Shreyas"
> salary=companydocs$empsalary
> salary
[1] 74000 78000 65000 86000 78500 69450

> id_name=[Link](companydocs[1:2,0:4])
> id_name
empid empname empsalary empstart_date
1 45 Tejas 74000 2023-08-25
2 46 Umang 78000 2023-08-24

> imp_data=companydocs[c(1,3),c(2,3)]
> imp_data
empname empsalary
1 Tejas 74000
3 Jidnesh 65000
Subject: MCAL13 Advanced Database Management System Academic Year First
Half 2022_23
Batch:2022_24
SIES College of Management Studies FYMCA (Revised), Sem I,
Roll No: 045

Assignment No. 1

 Q7. Create a vector “rating” with values “satisfied”, “not satisfied”, “highly satisfied”,
“Partly satisfied”, and “OK”. Convert “rating” to factor and store it in a variable
“Rating_factor” with and without proper order of levels. Print the value of a variable
“Rating_factor” and see the difference.

OUTPUT

> rating=c("Satisfied", "Not Satisfied", "Highly Satisfied", "Partly Satisfied", "OK")


> Rating_factor= factor(rating)
> Rating_factor
[1] Satisfied Not Satisfied Highly Satisfied Partly Satisfied
[5] OK
Levels: Highly Satisfied Not Satisfied OK Partly Satisfied Satisfied
> rating
[1] "Satisfied" "Not Satisfied" "Highly Satisfied"
[4] "Partly Satisfied" "OK"

Q8. Perform the following;


1. Create a list “lst” as follows: sequence of 1 to 10 as the first element, months abbreviation
as the second element, 3 by 3 identity matrix as the third element.
2. Print “lst”
3. Display the structure of “lst”
4. Access the month “Mar” from “lst”

OUTPUT

> First=list(c(1:10),c("Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept",
"Oct", "Nov", "Dec"),matrix(c(2,4,5,1,2,3,7,8,9),nrow=3,ncol=3))

> First
[[1]]
[1] 1 2 3 4 5 6 7 8 9 10

[[2]]
[1] "Jan" "Feb" "Mar" "Apr" "May" "June" "July" "Aug" "Sept" "Oct"
[11] "Nov" "Dec"

[[3]]
[,1] [,2] [,3]
[1,] 2 1 7
[2,] 4 2 8
[3,] 5 3 9

Subject: MCAL13 Advanced Database Management System Academic Year First


Half 2022_23
Batch:2022_24
SIES College of Management Studies FYMCA (Revised), Sem I,
Roll No: 045

Assignment No. 1
> str(First)
List of 3
$ : int [1:10] 1 2 3 4 5 6 7 8 9 10
$ : chr [1:12] "Jan" "Feb" "Mar" "Apr" ...
$ : num [1:3, 1:3] 2 4 5 1 2 3 7 8 9

> names(First)=c("Numbers","Months","Matrix")
> First$Months[3]
[1] "Mar"

Q9. Read and write data to csv file.

OUTPUT

> pointstable = [Link]("[Link]")


> pointstable
[Link] X X.1 X.2 X.3
1 Teams Played Win Lose Points
2 India 5 5 0 10
3 Australia 4 4 0 8
4 England 5 3 2 6
5 Pakistan 4 2 2 4
> knockouttable = [Link](Teams = c("Portugal", "Argentina", "France","Brazil"), Points
= c(20,18,18,16))
> knockouttable
Teams Points
1 Portugal 20
2 Argentina 18
3 France 18
4 Brazil 16
> [Link](knockouttable,"[Link]")

Subject: MCAL13 Advanced Database Management System Academic Year First


Half 2022_23
Batch:2022_24
SIES College of Management Studies FYMCA (Revised), Sem I,
Roll No: 045

Assignment No. 1

Q10. Read and write data in Excel file using readXL and writeXL. 
 

OUTPUT

> point_table = read_excel("[Link]")


> point_table
# A tibble: 5 × 5
`POINTS TABLE` ...2 ...3 ...4 ...5
<chr> <chr> <chr> <chr> <chr>
1 Teams Played Win Lose Points
2 India 5 5 0 10
3 Australia 4 4 0 8
4 England 5 3 2 6
5 Pakistan 4 2 2 4

> knockouttable = [Link](Teams = c("Portugal", "Argentina", "France","Brazil"), Points =


c(20,18,18,16))

> write_xlsx(knockouttable,"Knockout_table.xlsx")

Subject: MCAL13 Advanced Database Management System Academic Year First


Half 2022_23
Batch:2022_24

Common questions

Powered by AI

In R, 'Inf' represents infinity, usually resulting from division by zero, and is numeric type, allowing arithmetic operations. 'NaN' stands for 'Not a Number' and results from undefined mathematical operations, also a numeric type but indicates invalid computations. 'NA' signifies missing values with logical type, affecting data completeness analysis. An empty string ('') is character type and may signal incomplete data entry. Understanding these helps handle datasets accurately, ensuring valid and complete analyses .

Conditional data subsetting in R, exemplified by vector multiplication, allows targeted analysis by isolating relevant data meeting specific criteria, e.g., identifying elements exceeding defined thresholds. This enables focused computation, enhancing efficiency. It also facilitates anomaly detection and informative insight extraction from datasets, liaising with operations like sorting or filtering. Subsetting by conditions ensures computational resources are optimally used by processing only the necessary data, thus improving the efficiency and effectiveness of data manipulations .

To ensure a file directory is set correctly in R, you can use the getwd() function to get the current working directory and setwd() to change it to a desired directory. Verifying the directory change with getwd() again ensures the script runs in the correct environment. This process is critical for file management, helping maintain consistency and avoid errors in data paths .

Data frames in R offer a tabular structure ideal for organizing employee data, allowing integration of various data types per column such as numeric, character, and date. This mirrors spreadsheet data, enabling intuitive manipulation and analysis, e.g., selecting specific employee details or performing operations like sorting by salary. However, data frame operations might become less efficient with vast datasets, where memory becomes a concern. Advanced frameworks like data.table or dplyr may offer performance improvements over data frames for large-scale tasks .

Matrix operations in R, such as multiplication, transposing, and calculating determinants, are fundamental for linear algebra applications in data analysis. Multiplication assists in compactly solving linear equations, while transposing switches rows and columns, altering orientation without affecting content. The determinant offers insights into matrix properties, such as invertibility. These operations allow for efficient mathematical modeling and transformation, crucial in statistical algorithms, simulations, and computational optimization tasks .

Creating a factor from a character vector in R involves converting text values into factors using the factor() function, which is crucial for handling categorical data. Factors treat character strings as discrete values rather than text, allowing statistical analysis, such as computing frequency or relationship assessments. Proper ordering of levels in factors can affect data analysis, ensuring categories are evaluated in intended meaningful orders. This process transforms qualitative data into quantitative, enhancing data modeling capabilities .

The functions read.csv and write.csv in R facilitate data import/export. read.csv() reads CSV files into R as data frames, which is essential for data manipulation and analysis. write.csv() converses writing R data frames to CSV formats, ensuring data can be shared or stored systematically. It is crucial to correctly specify file paths and handle headers to avoid misalignment of data columns. Being cautious with separators and special characters is necessary to prevent file corruption or data misinterpretation .

The readxl and writexl packages offer user-friendly interfaces for handling Excel files in R. Unlike base functions, they do not require Java dependencies, improving ease of installation and cross-platform compatibility. readxl facilitates streamlined import of sheets including non-standard formats, while writexl ensures easy Excel output without auxiliary tools. These packages excel in data import/export speed and support various Excel versions, enhancing user experience and productivity in data transitions .

cbind() and rbind() functions in R bind vectors, lists, or data frames by columns and rows, respectively. cbind() results in columns aligning side-by-side, which is useful for structuring datasets in a wide format for comparative analysis. Conversely, rbind() stacks rows vertically, suitable for appending similar datasets. These functions facilitate logical structuring of data, enabling clear data organization and accessibility for further processing .

A list in R is a flexible data structure that can hold objects of different types and lengths, such as numbers, strings, vectors, and even other lists. Unlike vectors that contain elements of the same type, lists support heterogeneity, making them versatile for complex data. Lists allow inclusion of varied data types in structured form, providing robustness in organizing diverse datasets or outputs in a single object, which enhances capability for comprehensive data analysis .

You might also like