0% found this document useful (0 votes)
20 views

manish

The document contains a series of R programming commands for matrix operations, including creation, transposition, multiplication, and addition of matrices. It also demonstrates data frame creation and manipulation, as well as basic arithmetic operations on vectors. Additionally, it includes error handling for non-conformable arrays and showcases the use of indexing and conditional selection in R.

Uploaded by

xabc20815
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

manish

The document contains a series of R programming commands for matrix operations, including creation, transposition, multiplication, and addition of matrices. It also demonstrates data frame creation and manipulation, as well as basic arithmetic operations on vectors. Additionally, it includes error handling for non-conformable arrays and showcases the use of indexing and conditional selection in R.

Uploaded by

xabc20815
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

********/////////////a=matrix(c(7,18,-2,11,-18,3,33,1,9,-4,0,21),byrow=T,ncol=4);a

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

[1,] 7 18 -2 11

[2,] -18 3 33 1

[3,] 9 -4 0 21

> r=t(a);r

[,1] [,2] [,3]

[1,] 7 -18 9

[2,] 18 3 -4

[3,] -2 33 0

[4,] 11 1 21

> A=matrix(c(2,4,5,9,3,8),byrow=T,ncol=2);A;B=matrix(c(4,9),byrow=T,ncol=1);B

[,1] [,2]

[1,] 2 4

[2,] 5 9

[3,] 3 8

[,1]

[1,] 4

[2,] 9

> y=A*B;y

Error in A * B : non-conformable arrays

> K=A%*%B;K

[,1]

[1,] 44

[2,] 101

[3,] 84

> a=matrix(c(12,4,5,8,23,18),byrow=T,ncol=2);a;b=matrix(c(32,14,5,7,3,8),byrow=T,ncol=2);b

[,1] [,2]

[1,] 12 4
[2,] 5 8

[3,] 23 18

[,1] [,2]

[1,] 32 14

[2,] 5 7

[3,] 3 8

> D=a+b;D

[,1] [,2]

[1,] 44 18

[2,] 10 15

[3,] 26 26

> R=matrix(c(7,18,-2,-16,3,55,9,-4,0),byrow=T,ncol=3);R

[,1] [,2] [,3]

[1,] 7 18 -2

[2,] -16 3 55

[3,] 9 -4 0

> B=solve(R);

>B

[,1] [,2] [,3]

[1,] 0.021202776 0.000771010 0.09599075

[2,] 0.047706245 0.001734773 -0.03402082

[3,] 0.003565921 0.018311488 0.02978026

> R%*%B

[,1] [,2] [,3]

[1,] 1.000000e+00 3.469447e-17 6.245005e-17

[2,] 2.775558e-17 1.000000e+00 0.000000e+00

[3,] 0.000000e+00 1.335737e-16 1.000000e+00

> round(R%*%B,4)

[,1] [,2] [,3]


[1,] 1 0 0

[2,] 0 1 0

[3,] 0 0 1

> x=c(60,28,124)

> y=c(72,21,127)

> z=c(45,35,140)

> A=cbind(x,y,z);A

x y z

[1,] 60 72 45

[2,] 28 21 35

[3,] 124 127 140

> G=7*A;G

x y z

[1,] 420 504 315

[2,] 196 147 245

[3,] 868 889 980

> x=c(4,6,2,7,1,8)

> y=c(4,8)

> d=x+y

>d

[1] 8 14 6 15 5 16

> u=x/y;u

[1] 1.000 0.750 0.500 0.875 0.250 1.000

> o=x*y;o

[1] 16 48 8 56 4 64

> state=c(punjab,harayana,u.p,gujarat,bhihar,karnataka)

Error: object 'punjab' not found

> state=c("punjab","harayana","u.p","gujarat","bhihar","karnataka")

> wheat=c(728,1753,1475,1980,2210,2270)
> d=data.frame(state,wheat)

>d

state wheat

1 punjab 728

2 harayana 1753

3 u.p 1475

4 gujarat 1980

5 bhihar 2210

6 karnataka 2270

> d$state[3]

[1] "u.p"

> d$state[3];d$wheat[3]

[1] "u.p"

[1] 1475

> x=c(31,26,36,14,45,28,39,51,33,34,21,11,12,35,20)

>x

[1] 31 26 36 14 45 28 39 51 33 34 21 11 12 35 20

> y=c(36,39,51,12);y

[1] 36 39 51 12

> z=c(31,26,36,45,28,39,51,33,34,35);z

[1] 31 26 36 45 28 39 51 33 34 35

> x[c(1,3)]

[1] 31 36

> x[c(1,3,7,8,13)]

[1] 31 36 39 51 12

> x[x>25]

[1] 31 26 36 45 28 39 51 33 34 35

> marksofA=c(65,89,75,95,89);marksofA

[1] 65 89 75 95 89
> marksofB=c(52,69,70,81,85);marksofB

[1] 52 69 70 81 85

> d=data.frame(marksofA,marksofB)

>d

marksofA marksofB

1 65 52

2 89 69

3 75 70

4 95 81

5 89 85

> age=c(11,10,14,17,19,20,22,21);age

[1] 11 10 14 17 19 20 22 21

> age[age>15]

[1] 17 19 20 22 21

> age[age<20]

[1] 11 10 14 17 19

> y=c(18,25,age,21,24);y

[1] 18 25 11 10 14 17 19 20 22 21 21 24

>

> a=matrix(c(7,18,2,-16,3,55,9,-4,0);a

Error: unexpected ';' in "a=matrix(c(7,18,2,-16,3,55,9,-4,0);"

> a=matrix(c(7,18,2,-16,3,55,9,-4,0),byrow=T,ncol=3);a

[,1] [,2] [,3]

[1,] 7 18 2

[2,] -16 3 55

[3,] 9 -4 0

> G=10*a;G

[,1] [,2] [,3]

[1,] 70 180 20
[2,] -160 30 550

[3,] 90 -40 0

> A=matrix(c(6,10,15,19,34,81),byrow=T,ncol=2);A;B=matrix(c(3,4,5,10,39,8),byrow=T,ncol=2);B

[,1] [,2]

[1,] 6 10

[2,] 15 19

[3,] 34 81

[,1] [,2]

[1,] 3 4

[2,] 5 10

[3,] 39 8

> D=A+B;D

[,1] [,2]

[1,] 9 14

[2,] 20 29

[3,] 73 89

> a=matrix(c(17,18,-2,-16,20,55,9,-14,10),byrow=T,ncol=3);a

[,1] [,2] [,3]

[1,] 17 18 -2

[2,] -16 20 55

[3,] 9 -14 10

> R=t(a);R

[,1] [,2] [,3]

[1,] 17 -16 9

[2,] 18 20 -14

[3,] -2 55 10

> save.image("C:\\Users\\hp 2\\Documents\\manish")

You might also like