The Art of R Programming
The componentmatof this class will store the matrix. As mentioned, to save on storage space, only the diagonal and above-diagona ...
38 39 # multiply one ut matrix by another, returning another ut instance; 40 # implement as a binary operation 41 "%mut%" <- ...
test() [,1] [,2] [1,] 1 2 [2,] 0 2 [,1] [,2] [1,] 3 2 [2,] 0 1 [,1] [,2] [1,] 3 4 [2,] 0 2 [,1] [,2] [,3] [1,]123 [2,]012 [3,]0 ...
> row(m) [,1] [,2] [1,] 1 1 [2,] 2 2 [3,] 3 3 Thecol()function works similarly. Using this idea, we could replace theforloop ...
product can be expressed as a linear combination of the columns of the first factor. It will help to see a specific example of t ...
11 for (i in 1:maxdeg) { 12 lmo <- lm(y ~ pwrs[,1:i]) 13 # extend the lm class here, with the cross-validated predictions 14 ...
59 # the 1 accommodates the constant term 60 predy[i] <- betahat %% c(1,xmat[i,]) 61 } 62 return(predy) 63 } 64 65 # polynomi ...
Note first that we used a common R trick in this command: > (lmo <- polyfit(y,x,dg)) By surrounding the entire assignment ...
example, where our class"employee"had three fields:name,salary, andunion. Here are some possible mishaps: We forget to enter th ...
Slot "salary": [1] 55000 Slot "union": [1] TRUE Note that the member variables are calledslots, referenced via the@sym- bol. Her ...
As noted, an advantage of using S4 is safety. To illustrate this, suppose we were to accidentally spellsalaryassalry, like this: ...
Let’s try it out: > joe Joe has a salary of 55000 and is in the union 9.3 S3 Versus S4....................................... ...
ls() [1] "acc" "acc05" "binomci" "cmeans" "divorg" "dv" [7] "fit" "g" "genxc" "genxnt" "j" "lo" [13] "out1" "out1.100" "out1.25 ...
Here, we found two objects whose names include the string"notebook" and then asked to remove them, which was confirmed by the se ...
Let’s go through an example. R includes facilities for constructingcon- tingency tables, which we discussed in Section 6.4. An e ...
function, a lot of the function would zoom by on the screen too fast for us to absorb it. We could usepage()to solve this proble ...
10 INPUT/OUTPUT One of the most underemphasized topics in many university programming courses is input/output (I/O). I/O plays a ...
10.1 Accessing the Keyboard and Monitor......................................... R provides several functions for accesssing the ...
Read 4 items [1] "abc" "de" "f" "g" scan("z4.txt",what="") Read 4 items [1] "abc" "123" "6" "y" In the first call, we got a ve ...
You can usescan()to read from the keyboard by specifying an empty string for the filename: > v <- scan("") 1: 12 5 13 4:34 ...
«
8
9
10
11
12
13
14
15
16
17
»
Free download pdf