MATH319 Slides

168 Appendix B: R commands for matrices

Beware: R makes a meal of complex numbers, and is not a symbolic manipulation package.

>x<-3 [this assigns value x=3]

>t<-2 [this assigns value t=2]

>x*t [multiply x and t]

>x+t [add x and t]

>x/t [divide x by t]

>x^(-1.5) [raises x to the power -1.5]

>2*((x+t)^3) [computes 2(x+t)3]

>a<-c(5,9,7,-2) [creates vector a=(5,9,7,-2)]

>A<-array(a, dim=c(2,2)) [fills up a 2×2 matrix, column by column, from vector a]

>b<-c(1,4,2,5,3,6) [creates vector b=(1,4,2,5,3,6)]

>B<-array(b, dim=c(2,3)) [fills up a 2×3 matrix, column by column, from vector b]

>t(B) [forms the transpose of the matrix B]