The Art of R Programming
Browse[1]> i [1] 2 Browse[1]> x[i:(i+k-1)] [1]00 That’s right, too. We could go another iteration, but instead, let’s look ...
5 mind <- function(d) { 6 n <- nrow(d) 7 add a column to identify row number for apply() 8 dd <- cbind(d,1:n) 9 wmins & ...
where 1: eval(expr, envir, enclos) where 2: eval(quote(browser()), envir = sys.frame(which)) where 3 at cities.R#13: function () ...
There are several possibilities here. But since ultimatelyimin()is called, we can check them all from within that function. So, ...
But the valuej=2does not confirm. The minimum value in (0,12,5) is 5, which occurs at index 3 of that vector, not index 2. Thus, ...
Well, there are the 3 and 5 in column 1, just as should be the case. Remember, column 1 here contains the information for row 1 ...
through the code as you single-step through it. For example, consider this excerpt from our previous browser output: Browse[2]&g ...
NOTE Operation ofedtdbgfor Emacs is the same as shown here, just with different keystrokes used for the commands. For instance, ...
13.6 Syntax and Runtime Errors................................................... The most common syntax errors will be lack of ...
Although you can invoke R through GDB from a shell command line (see Section 15.1.4), for our purposes here, I suggest using sep ...
14 PERFORMANCE ENHANCEMENT: SPEED AND MEMORY In computer science curricula, a common theme is the trade-off between time and spa ...
This chapter will suggest ways that you can enhance the performance of your R code, taking into account the time/space trade-off ...
z <- vector(length=1000000) system.time(z <-x+y) user system elapsed 0.052 0.016 0.068 system.time(for (i in 1:length(x)) ...
0.012 0.000 0.015 > system.time( +{ + c <- 0 + for (i in 1:length(x)) + if (x[i] %% 2 == 1) c <- c+1 + return(c) +} +) ...
maxs <- pmax(xymat[,1],xymat[,2]) print(mean(maxs)) In this code, we generate all the random variates at once, storing them i ...
10 # pick from Urn 1 and put in Urn 2; is it blue? 11 if (runif(1) < nb1/n1) nb2 <- nb2 + 1 12 # pick from Urn 2; is it bl ...
[1] 0.5031 user system elapsed 2.936 0.004 3.027 In spite of the many benefits of functional programming, this approach usingapp ...
14.2.3 Extended Example: Generating a Powers Matrix................... Recall in Section 9.1.7, we needed to generate a matrix o ...
And yet,powers2()still contains a loop. Can we do better? It would seem that this setting is perfect forouter(), whose call form ...
14.3 Functional Programming and Memory Issues.................................. Most R objects areimmutable, or unchangeable. Th ...
«
12
13
14
15
16
17
18
19
20
21
»
Free download pdf