The Art of R Programming
What happened? The key point is that we are dealing with vectorization. Just like almost anything else in R,==is a function. "= ...
2.11 Vector Element Names...................................................... The elements of a vector can optionally be given ...
$a [1] 1 $b [1] 4 In the first example, we are mixing integer and character modes, a combination that R chooses to reduce to the ...
...
3 MATRICES AND ARRAYS Amatrixis a vector with two additional attributes: the number of rows and the number of columns. Since mat ...
One way to create a matrix is by using thematrix()function: > y <- matrix(c(1,2,3,4),nrow=2,ncol=2) >y [,1] [,2] [1,] 1 ...
Though internal storage of a matrix is in column-major order, you can set thebyrowargument inmatrix()to true to indicate that th ...
3.2.2 Matrix Indexing The same operations we discussed for vectors in Section 2.4.2 apply to matri- ces as well. Here’s an examp ...
Here, we assigned new values to the first and third rows ofy. And here’s another example of assignment to submatrices: x <- ...
Size : 194x259 Resolution : 1x1 Bounding box : 0 0 259 194 > plot(mtrush1) We read in the file namedmtrush1.pgm, returning an ...
waits for the user to click a point within a graph and returns the exact coordinates of that point. In this manner, I found that ...
As the comments indicate, we generate random noise and then take a weighted average of the target pixels and the noise. The para ...
Again, let’s dissect this, just as we did when we first looked at filtering in Chapter 2: j <- x[,2] >= 3 j [1] FALSE TRU ...
[1,] 1 4 [2,] 3 6 Here, the expressionz%%2==1tests each element ofzfor being an odd number, thus yielding(TRUE,FALSE,TRUE). As a ...
R informed us here that, from a vector-indexing point of view, elements 1, 3, 5, and 6 ofmare larger than 2. For example, elemen ...
Thus the expressionrow(m) == col(m)in the same line returns a matrix ofTRUEandFALSEvalues,TRUEvalues on the diagonal of the matr ...
apply(z,2,mean) [1]25 In this case, we could have used thecolMeans()function, but this pro- vides a simple example of usingapp ...
For instance, suppose we have a matrix of 1s and 0s and want to create a vector as follows: For each row of the matrix, the corr ...
deviant observation for each store. We’ll define that as the observation fur- thest from the median value for that store. Here’s ...
> x <- c(x[1:3],20,x[4:6]) # insert 20 >x [1] 12 5 13 20 16 8 20 > x <- x[-2:-4] # delete elements 2 through 4 &g ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf