Selecting and building matrices

Selecting parts of matrices

We can pick out specific elements, rows or columns of a data frame (can be numbers and/or characters) or of a matrix (just numbers) as in the following examples:
> gala[2,3]
> gala[2,]
> gala[,3]
We can construct new vectors using the c() command:
> c(2,4,6)
and select particular columns out of the matrix:
> gala[,c(2,4,6)]
or take everything but certain columns:
> gala[,-c(2,4,6)]

Question Suppose I'm not interested in the variable Endemics and I'd like to exclude the last island, Wolf, because perhaps there is something atypical about it. How would you create a new dataset without this variable and case? (Tip: use dim(gala) to find the dimensions of the matrix) 

Building matrices

Creating a vector of repeated elements is done using rep()
> rep(1,30)
and vectors and matrices can be bound together column-wise as in
> x <- cbind(rep(1,30),gala[,-c(1,2)])
> x
although
> cbind(1,gala[,-c(1,2)])
has the same effect. Other useful building commands are rbind() and seq() which is useful for creating sequences.



A few commands:

>t(A) would take Matrix Transpose

>solve(A) would take motrix inverse.