You are on page 1of 11

INTRODUCTION TO BUSINESS ANALYTICS

SYNTAX AND OUTPUTS


NAME: SUNIL KUMAR M

REG NO: 20202MDM0016

SECTION: G

1. LIST:

#create a list

list1<-list(c (3, 6, 9), 63.9, cos)

#print the list

Print (list1)

OUTPUT

> #creates a list


> list1<-list(c (3, 6, 9), 63.9, cos)
> #print the list
> print (list1)
[[1]]
[1] 3 6 9
[[2]]
[1] 63.9
[[3]]
Function (x) .Primitive ("cos”)
>
2. MATRIX

#create a matrix

M <- matrix(c (2:16), nrow = 3, byrow = TRUE)

Print (M)

#define the column and row names

Rownames = c ("row1","row2","row3","row4")

Colnames = c ("col1","col2","col3")

p <-matrix(c (2:16), nrow = 3, byrow = TRUE)

Print (p)

OUTPUT

> #creates a matrix

> M <- matrix(c (2:16), nrow =3, byrow =TRUE)

> print (M)

[, 1] [, 2] [, 3] [, 4] [, 5]

[1,] 2 3 4 5 6

[2,] 7 8 9 10 11

[3,] 12 13 14 15 16

> #defines the column and row names

> Rownames = c ("row1","row2","row3","row4")

> Colnames = c ("col1","col2","col3")

> p <- matrix(c (2:16), nrow =3, byrow = TRUE)

> print (p)

[, 1] [, 2] [, 3] [, 4] [, 5]
[1,] 2 3 4 5 6

[2,] 7 8 9 10 11

[3,] 12 13 14 15 16

>

3. VECTOR:

#create a vector

Sunil<-c ("ball","bat","stumps")

Print (sunil)

Print (class (sunil))

#vector

v1=11:20

Print (v1)

v2=20:11

Print (v2)

Print (v1+v2)

v3=c (12, 14, 16)

Print (v3)

OUTPUT

> #creates a vector


> Sunil<-c ("ball","bat","stumps")
> print (sunil)
[1] "ball" "bat" "stumps"
> print (class (sunil))
[1] "Character"
> #vector
> v1=11:20
> print (v1)
[1] 11 12 13 14 15 16 17 18 19 20
> v2=20:11
> print (v2)
[1] 20 19 18 17 16 15 14 13 12 11
> print (v1+v2)
[1] 31 31 31 31 31 31 31 31 31 31
> v3=c (12, 14, 16)
> print (v3)
[1] 12 14 16
>

4. ARITHEMATIC OPERATION:

#Arithematic operations
A = c (11, 41, 17, 31)
B = c (14, 38, 33, 48)
#Addition
A+B
#substraction
A-B
#multiplication
A*B
#Division
A/B
#Recycling Rule
X = c (10, 20, 30)
Z = c (1, 2, 3, 4, 5, 6, 7, 8, 9)
X+Z
A = c ()
OUTPUT

> #Arithematic operations

> A = c (11, 41, 17, 31)

> B = c (14, 38, 33, 48)

> #Addition

> A+B

[1] 25 79 50 79

> #substraction

> A-B

[1] -3 3 -16 -17

> #multiplication

> A*B

[1] 154 1558 561 1488

> #Division

> A/B

[1] 0.7857143 1.0789474 0.5151515 0.6458333

> #Recycling Rule

> X = c (10, 20, 30)

> Z = c (1, 2, 3, 4, 5, 6, 7, 8, 9)

> X+Z

[1] 11 22 33 14 25 36 17 28 39

> A = c ()

>
5. ADDITION,SUBSTRACTION,MULTIPLCATION AND DIVISION OF MATRIX

#Addition of matrix
A=matrix(c (11, 13, 15, 17, 19, 15), nrow = 2, ncol = 3)
Print (A)
B=matrix(c (22, 24, 26, 28, 24, 22), nrow = 2, ncol = 3)
Print (B)
#Add the matrix
Result<-A+B
Print (result)
#substraction of matrix
Result<-A-B
Print (result)
#multiplication of matrix
Result<-A*B
Print (result)
#Division of matrix
Result<-A/B
Print (result)

OUTPUT

> #Addition of matrix


> A=matrix(c (11, 13, 15, 17, 19, 15), nrow = 2,ncol = 3)
> Print (A)
[, 1] [, 2] [, 3]
[1,] 11 15 19
[2,] 13 17 15
> B=matrix(c (22, 24, 26, 28, 24, 22), nrow = 2,ncol = 3)
> print (B)
[, 1] [, 2] [, 3]
[1,] 22 26 24
[2,] 24 28 22
> #Add the matrix
> Result<-A+B

> print (result)


[, 1] [, 2] [, 3]
[1,] 33 41 43
[2,] 37 45 37
> #substraction of matrix
> Result<-A-B
> print (result)
[, 1] [, 2] [, 3]
[1,] -11 -11 -5
[2,] -11 -11 -7
> #multiplication of matrix
> Result<-A*B
> print (result)
[, 1] [, 2] [, 3]
[1,] 242 390 456
[2,] 312 476 330
> #Division of matrix
> Result<-A/B
> print (result)
[, 1] [, 2] [, 3]
[1,] 0.5000000 0.5769231 0.7916667
[2,] 0.5416667 0.6071429 0.6818182
>

6. STRING:

#to get the length of a text string


Str= "sunil"
nC=nchar(str)
Print (nc)
#to get the length of vector containing the string
v1 = c("sunil","suni")
Print (v1)
nstr = length (v1)
Print (nstr)
#TO find the min, max and range
x = c (5, 7, 9, 12, 13, 16)
Print(x)
Min(x)
Max(x)
Range(x)

OUTPUT
> #to get the length of a text string
> str= "sunil"
> nc=nchar (str)
> print (nc)
[1] 5

> #to get the length of vector containing the string


> v1 = c("sunil","suni")
> print (v1)
[1] "Sunil" "suni"
> nstr = length (v1)
> print (nstr)
[1] 2

> #TO find the min, max and range


> x = c (5, 7, 9, 12, 13, 16)
> Print(x)
[1] 5 7 9 12 13 16
> Min(x)
[1] 5
> Max(x)
[1] 16
> Range(x)
[1] 5 16
>
7. Data Frame

#create the data frame


BMI <- data. Frame (gender = c ("Male","Female","Male"),
Height = c (152,171.8, 167), weight = c (54, 60, 50),
Age = c (30, 32, 36))
Print (BMI)
#create the data frame of employee details
#creates a data frame of empid, empname, empdesgination,
empworkplace, empgender, empsalary, empmobilenumber.
CF<-data. Frame(empid = c(3,4,5),empname =
c("sam","sonu","nag"),empdesgination =
c("ceo","manager","clerk"),empworkplace =
c("goa","ap","up"),empsalary = c(1000,2000,3000),
empmobilenumber = c(4536785946,3546789756,3647586785),empgender
= c("male","female","male"))
Print (CF)

OUTPUT

#create the data frame


> BMI <- data. Frame (gender = c ("Male","Female","Male"),
+ Height = c (152,171.8, 167), weight = c (54, 60, 50),
Age = C(30,32,36) .... [TRUNCATED]

> print (BMI)


Gender height weight Age
1 Male 152.0 54 30
2 Female 171.8 60 32
3 Male 167.0 50 36

> #creates the data frame of employee details


> #creates a data frame of empid, empname, empdesgination,
empworkplace, empgender, empsalary, empmobilenumber....
[TRUNCATED]

> print (CF)


Empid empname empdesgination empworkplace empsalary
empmobilenumber empgender
1 3 sam CEO Goa 1000 4536785946 male
2 4 sonu manager AP 2000 3546789756 female
3 5 nag clerk up 3000 3647586785 male
>
8. ARRAY

#TO create an array with two elements


c <- array(c ("black","white"), dim = c (1, 2, 3))
Print(c)
c <- array(c (2:3), dim = c (4:5))
Print(c)
#to create an array of student marks
z <- array (c ("student marks"), dim = c(4:3))
Print (z)

OUTPUT

#TO create an array with two elements


> c <- array(c ("black","white"), dim = c (1, 2, 3))

> print(c)
,, 1

[, 1] [, 2]
[1,] "Black" "white"

,, 2

[, 1] [, 2]
[1,] "Black" "white"

,, 3

[, 1] [, 2]
[1,] "Black" "white"

> c <- array(c (2:3), dim = c (4:5))

> print(c)
[, 1] [, 2] [, 3] [, 4] [, 5]
[1,] 2 2 2 2 2
[2,] 3 3 3 3 3
[3,] 2 2 2 2 2
[4,] 3 3 3 3 3

> #to create an array of student marks


> z <- array (c ("student marks"), dim = c (4:3))

> print (z)


[, 1] [, 2] [, 3]
[1,] "Student marks" "student marks" "student marks"
[2,] "Student marks" "student marks" "student marks"
[3,] "Student marks" "student marks" "student marks"
[4,] "Student marks" "student marks" "student marks"
>

You might also like