In R programming pdf
In R programming pdf
Vectors
When you want to create vector with more than one element, you
should use c() function which means to combine the elements
into a vector.
Live Demo
# Create a vector.
apple <- c('red','green',"yellow")
print(apple)
Lists
A list is an R-object which can contain many different types of
elements inside it like vectors, functions and even another list
inside it.
Live Demo
# Create a list.
list1 <- list(c(2,5,3),21.3,sin)
[[1]]
[1] 2 5 3
[[2]]
[1] 21.3
[[3]]
function (x) .Primitive("sin")
Matrices
A matrix is a two-dimensional rectangular data set. It can be
created using a vector input to the matrix function.
Live Demo
# Create a matrix.
M = matrix( c('a','a','b','c','b','a'), nrow = 2, ncol
= 3, byrow = TRUE)
print(M)
Arrays
While matrices are confined to two dimensions, arrays can be of
any number of dimensions. The array function takes a dim
attribute which creates the required number of dimension. In the
below example we create an array with two elements which are
3x3 matrices each.
Live Demo
# Create an array.
a <- array(c('green','yellow'),dim = c(3,3,2))
print(a)
,,2
Factors
Factors are the r-objects which are created using a vector. It
stores the vector along with the distinct values of the elements in
the vector as labels. The labels are always character irrespective
of whether it is numeric or character or Boolean etc. in the input
vector. They are useful in statistical modeling.
Live Demo
# Create a vector.
apple_colors <-
c('green','green','yellow','red','red','red','green')
Data Frames
Data frames are tabular data objects. Unlike a matrix in data
frame each column can contain different modes of data. The first
column can be numeric while the second column can be character
and third column can be logical. It is a list of vectors of equal
length.
Live Demo
# Create the data frame.
BMI <- data.frame(
gender = c("Male", "Male","Female"),
height = c(152, 171.5, 165),
weight = c(81,93, 78),
Age = c(42,38,26)
)
print(BMI)
R VARIABLE
A variable provides us with named storage that our programs can
manipulate. A variable in R can store an atomic vector, group of
atomic vectors or a combination of many Robjects. A valid
variable name consists of letters, numbers and the dot or
underline characters. The variable name starts with a letter or the
dot not followed by a number.
Variable Assignment
The variables can be assigned values using leftward, rightward
and equal to operator. The values of the variables can be printed
using print() or cat() function. The cat() function combines
multiple items into a continuous print output.
Live Demo
# Assignment using equal operator.
var.1 = c(0,1,2,3)
print(var.1)
cat ("var.1 is ", var.1 ,"\n")
cat ("var.2 is ", var.2 ,"\n")
cat ("var.3 is ", var.3 ,"\n")
[1] 0 1 2 3
var.1 is 0 1 2 3
var.2 is learn R
var.3 is 1 1
Live Demo
var_x <- "Hello"
cat("The class of var_x is ",class(var_x),"\n")
Finding Variables
To know all the variables currently available in the workspace we
use the ls() function. Also the ls() function can use patterns to
match the variable names.
Live Demo
print(ls())
The ls() function can use patterns to match the variable names.
Live Demo
# List the variables starting with the pattern "var".
print(ls(pattern = "var"))
The variables starting with dot(.) are hidden, they can be listed
using "all.names = TRUE" argument to ls() function.
Live Demo
print(ls(all.name = TRUE))
Deleting Variables
Variables can be deleted by using the rm() function. Below we
delete the variable var.3. On printing the value of the variable
error is thrown.
Live Demo
rm(var.3)
print(var.3)
[1] "var.3"
Error in print(var.3) : object 'var.3' not found
Live Demo
rm(list = ls())
print(ls())
character(0)
R - Operators
Types of Operators
We have the following types of operators in R programming −
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Assignment Operators
• Miscellaneous Operators
Arithmetic Operators
Following table shows the arithmetic operators supported by R
language. The operators act on each element of the vector.
Live Demo
v <- c( 2,5.5,6)
+ Adds two vectors t <- c(8, 3, 4)
print(v+t)
it produces the following result −
[1] 10.0 8.5 10.0
Live Demo
v <- c( 2,5.5,6)
Subtracts second vector from
− t <- c(8, 3, 4)
the first print(v-t)
it produces the following result −
[1] -6.0 2.5 2.0
Live Demo
v <- c( 2,5.5,6)
* Multiplies both vectors t <- c(8, 3, 4)
print(v*t)
it produces the following result −
[1] 16.0 16.5 24.0
Live Demo
v <- c( 2,5.5,6)
Divide the first vector with t <- c(8, 3, 4)
/
the second print(v/t)
When we execute the above code, it
produces the following result −
[1] 0.250000 1.833333 1.500000
Live Demo
v <- c( 2,5.5,6)
Give the remainder of the
%% t <- c(8, 3, 4)
first vector with the second print(v%%t)
it produces the following result −
[1] 2.0 2.5 2.0
Live Demo
v <- c( 2,5.5,6)
The result of division of first
%/% t <- c(8, 3, 4)
vector with second (quotient) print(v%/%t)
it produces the following result −
[1] 0 1 1
Live Demo
v <- c( 2,5.5,6)
The first vector raised to the
^ t <- c(8, 3, 4)
exponent of second vector print(v^t)
it produces the following result −
[1] 256.000 166.375 1296.000
Relational Operators
Following table shows the relational operators supported by R
language. Each element of the first vector is compared with the
corresponding element of the second vector. The result of
comparison is a Boolean value.
Live Demo
Checks if each element
of the first vector is v <- c(2,5.5,6,9)
> greater than the t <- c(8,2.5,14,9)
corresponding element print(v>t)
of the second vector. it produces the following result −
[1] FALSE TRUE FALSE FALSE
Live Demo
Checks if each element
of the first vector is less v <- c(2,5.5,6,9)
< than the corresponding t <- c(8,2.5,14,9)
element of the second print(v < t)
vector. it produces the following result −
[1] TRUE FALSE TRUE FALSE
Live Demo
Checks if each element
== of the first vector is v <- c(2,5.5,6,9)
equal to the t <- c(8,2.5,14,9)
print(v == t)
corresponding element it produces the following result −
of the second vector. [1] FALSE FALSE FALSE TRUE
Live Demo
Checks if each element
of the first vector is less v <- c(2,5.5,6,9)
<= than or equal to the t <- c(8,2.5,14,9)
corresponding element print(v<=t)
of the second vector. it produces the following result −
[1] TRUE FALSE TRUE TRUE
Live Demo
Checks if each element
of the first vector is v <- c(2,5.5,6,9)
!= unequal to the t <- c(8,2.5,14,9)
corresponding element print(v!=t)
of the second vector. it produces the following result −
[1] TRUE TRUE TRUE FALSE
Logical Operators
Following table shows the logical operators supported by R
language. It is applicable only to vectors of type logical, numeric
or complex. All numbers greater than 1 are considered as logical
value TRUE.
It is called Element-wise
Logical OR operator. It Live Demo
combines each element
of the first vector with v <- c(3,0,TRUE,2+2i)
| the corresponding t <- c(4,0,FALSE,2+3i)
element of the second print(v|t)
vector and gives a it produces the following result −
output TRUE if one the [1] TRUE FALSE TRUE TRUE
elements is TRUE.
The logical operator && and || considers only the first element of
the vectors and give a vector of single element as output.
Live Demo
Called Logical AND operator.
v <- c(3,0,TRUE,2+2i)
Takes first element of both the
&& t <- c(1,3,TRUE,2+3i)
vectors and gives the TRUE print(v&&t)
only if both are TRUE.
it produces the following result −
[1] TRUE
Live Demo
Called Logical OR operator.
v <- c(0,0,TRUE,2+2i)
Takes first element of both the
|| t <- c(0,3,TRUE,2+3i)
vectors and gives the TRUE if print(v||t)
one of them is TRUE.
it produces the following result −
[1] FALSE
Assignment Operators
These operators are used to assign values to vectors.
Live Demo
v1 <- c(3,1,TRUE,2+3i)
v2 <<- c(3,1,TRUE,2+3i)
<− v3 = c(3,1,TRUE,2+3i)
or print(v1)
= Called Left Assignment print(v2)
or print(v3)
<<− it produces the following result −
[1] 3+0i 1+0i 1+0i 2+3i
[1] 3+0i 1+0i 1+0i 2+3i
[1] 3+0i 1+0i 1+0i 2+3i
Live Demo
c(3,1,TRUE,2+3i) -> v1
c(3,1,TRUE,2+3i) ->> v2
-> print(v1)
or Called Right Assignment
print(v2)
->>
it produces the following result −
[1] 3+0i 1+0i 1+0i 2+3i
[1] 3+0i 1+0i 1+0i 2+3i
Miscellaneous Operators
These operators are used to for specific purpose and not general
mathematical or logical computation.
Live Demo
R - Decision making
if statement
1
An if statement consists of a Boolean expression followed by one or
more statements.
if...else statement
2
An if statement can be followed by an optional else statement,
which executes when the Boolean expression is false.
switch statement
3
A switch statement allows a variable to be tested for equality
against a list of values.
R - If Statement
Syntax
The basic syntax for creating an if statement in R is −
if(boolean_expression) {
// statement(s) will execute if the boolean expression is true.
}
Flow Diagram
Example
Live Demo
x <- 30L
if(is.integer(x)) {
print("X is an Integer")
}
Syntax
The basic syntax for creating an if...else statement in R is −
if(boolean_expression) {
// statement(s) will execute if the boolean expression is true.
} else {
// statement(s) will execute if the boolean expression is false.
}
Flow Diagram
Example
Live Demo
x <- c("what","is","truth")
if("Truth" %in% x) {
print("Truth is found")
} else {
print("Truth is not found")
}
When using if, else if, else statements there are few points to keep
in mind.
Syntax
The basic syntax for creating an if...else if...else statement in R is −
if(boolean_expression 1) {
// Executes when the boolean expression 1 is true.
} else if( boolean_expression 2) {
// Executes when the boolean expression 2 is true.
} else if( boolean_expression 3) {
// Executes when the boolean expression 3 is true.
} else {
// executes when none of the above condition is true.
}
Example
Live Demo
x <- c("what","is","truth")
if("Truth" %in% x) {
print("Truth is found the first time")
} else if ("truth" %in% x) {
print("truth is found the second time")
} else {
print("No truth found")
}
R - Switch Statement
Syntax
The basic syntax for creating a switch statement in R is −
Flow Diagram
Example
Live Demo
x <- switch(
3,
"first",
"second",
"third",
"fourth"
)
print(x)
When the above code is compiled and executed, it produces the
following result −
[1] "third"
R - Loops
while loop
2
Repeats a statement or group of statements while a given condition is
true. It tests the condition before executing the loop body.
for loop
3
Like a while statement, except that it tests the condition at the end of
the loop body.
break statement
1
Terminates the loop statement and transfers execution to the
statement immediately following the loop.
Next statement
2
The next statement simulates the behavior of R switch.
R - Repeat Loop
Previous
Next
The Repeat loop executes the same code again and again until a
stop condition is met.
Syntax
The basic syntax for creating a repeat loop in R is −
repeat {
commands
if(condition) {
break
}
}
Flow Diagram
Example
Live Demo
v <- c("Hello","loop")
cnt <- 2
repeat {
print(v)
cnt <- cnt+1
if(cnt > 5) {
break
}
}
R - While Loop
The While loop executes the same code again and again until a
stop condition is met.
Syntax
The basic syntax for creating a while loop in R is −
while (test_expression) {
statement
}
Flow Diagram
Here key point of the while loop is that the loop might not ever
run. When the condition is tested and the result is false, the loop
body will be skipped and the first statement after the while loop
will be executed.
Example
Live Demo
v <- c("Hello","while loop")
cnt <- 2
R - For Loop
Syntax
The basic syntax for creating a for loop statement in R is −
Flow Diagram
R’s for loops are particularly flexible in that they are not limited to
integers, or even numbers in the input. We can pass character
vectors, logical vectors, lists or expressions.
Example
Live Demo
v <- LETTERS[1:4]
for ( i in v) {
print(i)
}
[1] "A"
[1] "B"
[1] "C"
[1] "D"
R - Break Statement
Syntax
The basic syntax for creating a break statement in R is −
break
Flow Diagram
Example
Live Demo
v <- c("Hello","loop")
cnt <- 2
repeat {
print(v)
cnt <- cnt + 1
if(cnt > 5) {
break
}
}
Syntax
The basic syntax for creating a next statement in R is −
next
Flow Diagram
Example
Live Demo
v <- LETTERS[1:6]
for ( i in v) {
if (i == "D") {
next
}
print(i)
}
When the above code is compiled and executed, it produces the
following result −
[1] "A"
[1] "B"
[1] "C"
[1] "E"
[1] "F"
R - Functions
The function in turn performs its task and returns control to the
interpreter as well as any result which may be stored in other
objects.
Function Definition
An R function is created by using the keyword function. The basic
syntax of an R function definition is as follows −
Function Components
The different parts of a function are −
Built-in Function
Simple examples of in-built functions
are seq(), mean(), max(), sum(x) and paste(...) etc. They are
directly called by user written programs. You can refer most
widely used R functions.
Live Demo
# Create a sequence of numbers from 32 to 44.
print(seq(32,44))
[1] 32 33 34 35 36 37 38 39 40 41 42 43 44
[1] 53.5
[1] 1526
User-defined Function
We can create user-defined functions in R. They are specific to
what a user wants and once created they can be used like the
built-in functions. Below is an example of how a function is
created and used.
# Create a function to print squares of numbers in
sequence.
new.function <- function(a) {
for(i in 1:a) {
b <- i^2
print(b)
}
}
Calling a Function
Live Demo
# Create a function to print squares of numbers in
sequence.
new.function <- function(a) {
for(i in 1:a) {
b <- i^2
print(b)
}
}
[1] 1
[1] 4
[1] 9
[1] 16
[1] 25
[1] 36
Calling a Function without an Argument
Live Demo
# Create a function without an argument.
new.function <- function() {
for(i in 1:5) {
print(i^2)
}
}
[1] 1
[1] 4
[1] 9
[1] 16
[1] 25
Calling a Function with Argument Values (by position
and by name)
Live Demo
# Create a function with arguments.
new.function <- function(a,b,c) {
result <- a * b + c
print(result)
}
[1] 26
[1] 58
Calling a Function with Default Argument
Live Demo
# Create a function with arguments.
new.function <- function(a = 3, b = 6) {
result <- a * b
print(result)
}
[1] 18
[1] 45
Live Demo
# Create a function with arguments.
new.function <- function(a, b) {
print(a^2)
print(a)
print(b)
}
R - Strings
Live Demo
a <- 'Start and end with single quote'
print(a)
String Manipulation
Concatenating Strings - paste() function
Syntax
print(paste(a,b,c))
Syntax
format(x, digits, nsmall, scientific, width, justify = c("left", "right", "centre", "none"))
[1] "23.1234568"
[1] "6.000000e+00" "1.314521e+01"
[1] "23.47000"
[1] "6"
[1] " 13.7"
[1] "Hello "
[1] " Hello "
Counting number of characters in a string - nchar()
function
Syntax
nchar(x)
[1] 30
Changing the case - toupper() & tolower() functions
Syntax
toupper(x)
tolower(x)
Syntax
substring(x,first,last)
[1] "act"
R - Vectors
Vectors are the most basic R data objects and there are six types
of atomic vectors. They are logical, integer, double, complex,
character and raw.
Vector Creation
Single Element Vector
Live Demo
# Atomic vector of type character.
print("abc");
[1] "abc"
[1] 12.5
[1] 63
[1] TRUE
[1] 2+3i
[1] 68 65 6c 6c 6f
Multiple Elements Vector
Live Demo
# Creating a sequence from 5 to 13.
v <- 5:13
print(v)
[1] 5 6 7 8 9 10 11 12 13
[1] 6.6 7.6 8.6 9.6 10.6 11.6 12.6
[1] 3.8 4.8 5.8 6.8 7.8 8.8 9.8 10.8
Live Demo
# Create vector with elements from 5 to 9 incrementing
by 0.4.
print(seq(5, 9, by = 0.4))
[1] 5.0 5.4 5.8 6.2 6.6 7.0 7.4 7.8 8.2 8.6 9.0
Live Demo
# Accessing vector elements using position.
t <- c("Sun","Mon","Tue","Wed","Thurs","Fri","Sat")
u <- t[c(2,3,6)]
print(u)
Vector Manipulation
Vector arithmetic
Live Demo
# Create two vectors.
v1 <- c(3,8,4,5,0,11)
v2 <- c(4,11,0,8,1,2)
# Vector addition.
add.result <- v1+v2
print(add.result)
# Vector subtraction.
sub.result <- v1-v2
print(sub.result)
# Vector multiplication.
multi.result <- v1*v2
print(multi.result)
# Vector division.
divi.result <- v1/v2
print(divi.result)
[1] 7 19 4 13 1 13
[1] -1 -3 4 -3 -1 9
[1] 12 88 0 40 0 22
[1] 0.7500000 0.7272727 Inf 0.6250000 0.0000000 5.5000000
Vector Element Recycling
[1] 7 19 8 16 4 22
[1] -1 -3 0 -6 -4 0
Vector Element Sorting
Live Demo
v <- c(3,8,4,5,0,11, -9, 304)
R - Lists
Creating a List
Following is an example to create a list containing strings,
numbers, vectors and a logical values.
Live Demo
# Create a list containing strings, numbers, vectors
and a logical
# values.
list_data <- list("Red", "Green", c(21,32,11), TRUE,
51.23, 119.1)
print(list_data)
[[1]]
[1] "Red"
[[2]]
[1] "Green"
[[3]]
[1] 21 32 11
[[4]]
[1] TRUE
[[5]]
[1] 51.23
[[6]]
[1] 119.1
Live Demo
# Create a list containing a vector, a matrix and a
list.
list_data <- list(c("Jan","Feb","Mar"),
matrix(c(3,9,5,1,-2,8), nrow = 2),
list("green",12.3))
$`1st_Quarter`
[1] "Jan" "Feb" "Mar"
$A_Matrix
[,1] [,2] [,3]
[1,] 3 5 -2
[2,] 9 1 8
$A_Inner_list
$A_Inner_list[[1]]
[1] "green"
$A_Inner_list[[2]]
[1] 12.3
Live Demo
# Create a list containing a vector, a matrix and a
list.
list_data <- list(c("Jan","Feb","Mar"),
matrix(c(3,9,5,1,-2,8), nrow = 2),
list("green",12.3))
$`1st_Quarter`
[1] "Jan" "Feb" "Mar"
$A_Inner_list
$A_Inner_list[[1]]
[1] "green"
$A_Inner_list[[2]]
[1] 12.3
Live Demo
# Create a list containing a vector, a matrix and a
list.
list_data <- list(c("Jan","Feb","Mar"),
matrix(c(3,9,5,1,-2,8), nrow = 2),
list("green",12.3))
[[1]]
[1] "New element"
$<NA>
NULL
Merging Lists
You can merge many lists into one list by placing all the lists
inside one list() function.
Live Demo
# Create two lists.
list1 <- list(1,2,3)
list2 <- list("Sun","Mon","Tue")
[[1]]
[1] 1
[[2]]
[1] 2
[[3]]
[1] 3
[[4]]
[1] "Sun"
[[5]]
[1] "Mon"
[[6]]
[1] "Tue"
Live Demo
# Create lists.
list1 <- list(1:5)
print(list1)
list2 <-list(10:14)
print(list2)
print(v1)
print(v2)
[[1]]
[1] 1 2 3 4 5
[[1]]
[1] 10 11 12 13 14
[1] 1 2 3 4 5
[1] 10 11 12 13 14
[1] 11 13 15 17 19
R - Matrices
Syntax
Live Demo
# Elements are arranged sequentially by row.
M <- matrix(c(3:14), nrow = 4, byrow = TRUE)
print(M)
Live Demo
# Define the column and row names.
rownames = c("row1", "row2", "row3", "row4")
colnames = c("col1", "col2", "col3")
[1] 5
[1] 13
col1 col2 col3
6 7 8
row1 row2 row3 row4
5 8 11 14
Matrix Computations
Various mathematical operations are performed on the matrices
using the R operators. The result of the operation is also a
matrix.
R - Arrays
Arrays are the R data objects which can store data in more than
two dimensions. For example − If we create an array of
dimension (2, 3, 4) then it creates 4 rectangular matrices each
with 2 rows and 3 columns. Arrays can store only data type.
Example
The following example creates an array of two 3x3 matrices each
with 3 rows and 3 columns.
Live Demo
# Create two vectors of different lengths.
vector1 <- c(5,9,3)
vector2 <- c(10,11,12,13,14,15)
,,1
,,2
Live Demo
# Create two vectors of different lengths.
vector1 <- c(5,9,3)
vector2 <- c(10,11,12,13,14,15)
column.names <- c("COL1","COL2","COL3")
row.names <- c("ROW1","ROW2","ROW3")
matrix.names <- c("Matrix1","Matrix2")
, , Matrix1
, , Matrix2
Live Demo
# Create two vectors of different lengths.
vector1 <- c(5,9,3)
vector2 <- c(10,11,12,13,14,15)
Syntax
apply(x, margin, fun)
• x is an array.
• margin is the name of the data set used.
• fun is the function to be applied across the elements of the
array.
Example
Live Demo
# Create two vectors of different lengths.
vector1 <- c(5,9,3)
vector2 <- c(10,11,12,13,14,15)
,,1
,,2
[1] 56 68 60
R - Factors
Factors are the data objects which are used to categorize the
data and store it as levels. They can store both strings and
integers. They are useful in the columns which have a limited
number of unique values. Like "Male, "Female" and True, False
etc. They are useful in data analysis for statistical modeling.
Example
Live Demo
# Create a vector as input.
data <-
c("East","West","East","North","North","East","West","W
est","West","East","North")
print(data)
print(is.factor(data))
print(factor_data)
print(is.factor(factor_data))
[1] "East" "West" "East" "North" "North" "East" "West" "West" "West" "East" "North"
[1] FALSE
[1] East West East North North East West West West East North
Levels: East North West
[1] TRUE
Live Demo
# Create the vectors for data frame.
height <- c(132,151,162,139,166,147,122)
weight <- c(48,49,66,53,67,52,40)
gender <-
c("male","male","female","female","male","female","male
")
Live Demo
data <-
c("East","West","East","North","North","East","West",
"West","West","East","North")
# Create the factors
factor_data <- factor(data)
print(factor_data)
[1] East West East North North East West West West East North
Levels: East North West
[1] East West East North North East West West West East North
Levels: East West North
Syntax
gl(n, k, labels)
R - Data Frames
Live Demo
# Create the data frame.
emp.data <- data.frame(
emp_id = c (1:5),
emp_name = c("Rick","Dan","Michelle","Ryan","Gary"),
salary = c(623.3,515.2,611.0,729.0,843.25),
Live Demo
# Create the data frame.
emp.data <- data.frame(
emp_id = c (1:5),
emp_name = c("Rick","Dan","Michelle","Ryan","Gary"),
salary = c(623.3,515.2,611.0,729.0,843.25),
Live Demo
# Create the data frame.
emp.data <- data.frame(
emp_id = c (1:5),
emp_name = c("Rick","Dan","Michelle","Ryan","Gary"),
salary = c(623.3,515.2,611.0,729.0,843.25),
start_date = as.Date(c("2012-01-01","2013-09-
23","2014-11-15","2014-05-11",
"2015-03-27")),
stringsAsFactors = FALSE
)
# Extract Specific columns.
result <- data.frame(emp.data$emp_name,emp.data$salary)
print(result)
emp.data.emp_name emp.data.salary
1 Rick 623.30
2 Dan 515.20
3 Michelle 611.00
4 Ryan 729.00
5 Gary 843.25
Live Demo
# Create the data frame.
emp.data <- data.frame(
emp_id = c (1:5),
emp_name = c("Rick","Dan","Michelle","Ryan","Gary"),
salary = c(623.3,515.2,611.0,729.0,843.25),
Extract 3rd and 5th row with 2nd and 4th column
Live Demo
# Create the data frame.
emp.data <- data.frame(
emp_id = c (1:5),
emp_name = c("Rick","Dan","Michelle","Ryan","Gary"),
salary = c(623.3,515.2,611.0,729.0,843.25),
# Extract 3rd and 5th row with 2nd and 4th column.
result <- emp.data[c(3,5),c(2,4)]
print(result)
emp_name start_date
3 Michelle 2014-11-15
5 Gary 2015-03-27
Live Demo
# Create the data frame.
emp.data <- data.frame(
emp_id = c (1:5),
emp_name = c("Rick","Dan","Michelle","Ryan","Gary"),
salary = c(623.3,515.2,611.0,729.0,843.25),
In the example below we create a data frame with new rows and
merge it with the existing data frame to create the final data
frame.
Live Demo
# Create the first data frame.
emp.data <- data.frame(
emp_id = c (1:5),
emp_name = c("Rick","Dan","Michelle","Ryan","Gary"),
salary = c(623.3,515.2,611.0,729.0,843.25),