12.07.2015 Views

R dummies

R dummies

R dummies

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

They contain only a single type of value.They have dimensions.The dimensions of an array determine the type of the array. You know alreadythat a vector has only one dimension. An array with two dimensions is a matrix.Anything with more than two dimensions is simply called an array. You find agraphical representation of this in Figure 7-1.Technically, a vector has no dimensions at all in R. If you use the functionsdim(), nrow(), or ncol(), mentioned in the “Looking at the properties” section,later in this chapter, with a vector as argument, R returns NULL as a result.Figure 7-1: A vector, a matrix, and an array.Creating your first matrixCreating a matrix is almost as easy as writing the word: You simply use thematrix() function. You do have to give R a little bit more information, though. Rneeds to know which values you want to put in the matrix and how you want to putthem in. The matrix() function has a couple arguments to control this:data is a vector of values you want in the matrix.ncol takes a single number that tells R how many columns you want.nrow takes a single number that tells R how many rows you want.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!