School of Economics and Management
Beihang University
http://yanfei.site

Control structures

Commonly used control structures

  • if and else: testing a condition and acting on it

  • for: execute a loop a fixed number of times

  • while: execute a loop while a condition is true

  • repeat: execute an infinite loop (must break out of it to stop)

  • break: break the execution of a loop

  • next: skip an interation of a loop

if-else

The if-else combination is probably the most commonly used control structure in R (or perhaps any language). For starters, you can just use the if statement.

if(<condition>) {
        ## do something
} 
## Continue with rest of code

if-else

If you have an action you want to execute when the condition is false, then you need an else clause.

if(<condition>) {
        ## do something
} 
else {
        ## do something else
}

You can have a series of tests by following the initial if with any number of else ifs.

if(<condition1>) {
        ## do something
} else if(<condition2>)  {
        ## do something different
} else {
        ## do something different
}

if-else Example

## Generate a uniform random number
x <- runif(1, 0, 10)
if (x > 3) {
    y <- 10
} else {
    y <- 0
}

Or you can write:

y <- if (x > 3) {
    10
} else {
    0
}

for Loops

For loops are most commonly used for iterating over the elements of an object (list, vector, etc.)

for (i in 1:10) {
    print(i)
}
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
## [1] 9
## [1] 10

for Loops Example

The following three loops all have the same behavior.

x <- c("a", "b", "c", "d")
for (i in 1:4) {
    ## Print out each element of 'x'
    print(x[i])
}
## [1] "a"
## [1] "b"
## [1] "c"
## [1] "d"

The seq_along() function is commonly used in conjunction with for loops in order to generate an integer sequence based on the length of an object (in this case, the object x).

## Generate a sequence based on length of 'x'
for (i in seq_along(x)) {
    print(x[i])
}
## [1] "a"
## [1] "b"
## [1] "c"
## [1] "d"

It is not necessary to use an index-type variable.

for (letter in x) {
    print(letter)
}
## [1] "a"
## [1] "b"
## [1] "c"
## [1] "d"

Nested for loops

for loops can be nested inside of each other.

x <- matrix(1:6, 2, 3)
for(i in seq_len(nrow(x))) {
        for(j in seq_len(ncol(x))) {
                print(x[i, j])
        }   
}

Nested loops are commonly needed for multidimensional or hierarchical data structures (e.g. matrices, lists).

while Loops

While loops begin by testing a condition. If it is true, then they execute the loop body. Once the loop body is executed, the condition is tested again, and so forth, until the condition is false, after which the loop exits.

count <- 0
while (count < 10) {
    print(count)
    count <- count + 1
}
## [1] 0
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
## [1] 9

While loops can potentially result in infinite loops if not written properly. Use with care!

repeat Loops

repeat initiates an infinite loop right from the start. The only way to exit a repeat loop is to call break.

x0 <- 1
tol <- 1e-08
repeat {
    x1 <- computeEstimate()
    
    if (abs(x1 - x0) < tol) {
        ## Close enough?
        break
    } else {
        x0 <- x1
    }
}

next, break

next is used to skip an iteration of a loop.

for (i in 1:100) {
    if (i <= 20) {
        ## Skip the first 20 iterations
        next
    }
    ## Do something here
}

break is used to exit a loop immediately, regardless of what iteration the loop may be on.

for (i in 1:100) {
    print(i)
    if (i > 20) {
        ## Stop loop after 20 iterations
        break
    }
}

Summary

  • Control structures like if, while, and for allow you to control the flow of an R program

  • Infinite loops should generally be avoided, even if (you believe) they are theoretically correct.

  • Control structures mentioned here are primarily useful for writing programs; for command-line interactive work, the "apply" functions are more useful.

Functions

Functions

  • A transition from a mere "user" to a developer!
  • Often used to encapsulate a sequence of expressions that need to be executed numerous times, perhaps under slightly different conditions.
  • Often written when code must be shared with others or the public.

Your First Function

Functions are defined using the function() directive and are stored as R objects just like anything else. In particular, they are R objects of class "function".

f <- function() {
    cat("Hello, world!\n")
}
f()
## Hello, world!

The last aspect of a basic function is the function arguments.

f <- function(num) {
    for (i in seq_len(num)) {
        cat("Hello, world!\n")
    }
}
f(3)
## Hello, world!
## Hello, world!
## Hello, world!

When to Write a Function?

If you find yourself doing a lot of cutting and pasting, that's usually a good sign that you might need to write a function.

This next function returns the total number of characters printed to the console.

f <- function(num) {
    hello <- "Hello, world!\n"
    for (i in seq_len(num)) {
        cat(hello)
    }
    chars <- nchar(hello) * num
    chars
}
meaningoflife <- f(3)
## Hello, world!
## Hello, world!
## Hello, world!
print(meaningoflife)
## [1] 42

Default Values

Try this:

f()

We can modify this behavior by setting a default value for the argument num.

f <- function(num = 1) {
    hello <- "Hello, world!\n"
    for (i in seq_len(num)) {
        cat(hello)
    }
    chars <- nchar(hello) * num
    chars
}
f()  ## Use default value for 'num'
## Hello, world!
## [1] 14
f(2)  ## Use user-specified value
## Hello, world!
## Hello, world!
## [1] 28

At this point, we have written a function that

  • has one formal argument named num with a default value of 1. The formal arguments are the arguments included in the function definition. The formals() function returns a list of all the formal arguments of a function

  • prints the message "Hello, world!" to the console a number of times indicated by the argument num

  • returns the number of characters printed to the console

Argument Matching

R assigns the first value to the first argument, the second value to second argument, etc. So in the following call to rnorm()

str(rnorm)
## function (n, mean = 0, sd = 1)
mydata <- rnorm(100, 2, 1)  ## Generate some data

100 is assigned to the n argument, 2 is assigned to the mean argument, and 1 is assigned to the sd argument, all by positional matching.

## Positional match first argument, default for 'na.rm'
sd(mydata)
## [1] 1.028851
## Specify 'x' argument by name, default for 'na.rm'
sd(x = mydata)
## [1] 1.028851
## Specify both arguments by name
sd(x = mydata, na.rm = FALSE)
## [1] 1.028851

When specifying the function arguments by name, it doesn't matter in what order you specify them.

## Specify both arguments by name
sd(na.rm = FALSE, x = mydata)
## [1] 1.028851

You can mix positional matching with matching by name.

sd(na.rm = FALSE, mydata)
## [1] 1.028851

Here, the mydata object is assigned to the x argument, because it's the only argument not yet specified.

Below is the argument list for the lm() function, which fits linear models to a dataset.

args(lm)
## function (formula, data, subset, weights, na.action, method = "qr", 
##     model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE, 
##     contrasts = NULL, offset, ...) 
## NULL

The following two calls are equivalent.

lm(data = mydata, y ~ x, model = FALSE, 1:100)
lm(y ~ x, mydata, 1:100, model = FALSE)

Function arguments can also be partially matched, which is useful for interactive work. The order of operations when given an argument is

  1. Check for exact match for a named argument
  2. Check for a partial match
  3. Check for a positional match

The ... Argument

  • There is a special argument in R known as the ... argument, which indicate a variable number of arguments that are usually passed on to other functions.
  • The ... argument is often used when extending another function and you don’t want to copy the entire argument list of the original function

  • For example, a custom mean function may want to make use of the default mean() function along with its entire argument list. The function below changes the default for the na.rm argument to the value na.rm = "TRUE" (the original default was na.rm = "FALSE").

mymean <- function(x, na.rm = TRUE, ...) {
        mean(x, na.rm = na.rm, ...)         ## Pass '...' to 'mean?rnorm' function
}
x <- c(1, 2, NA)
mean(x)
mymean(x)

Summary

  • Functions can be defined using the function() directive and are assigned to R objects just like any other R object

  • Functions have can be defined with named arguments; these function arguments can have default values

  • Functions arguments can be specified by name or by position in the argument list

  • Functions always return the last expression evaluated in the function body

  • A variable number of arguments can be specified using the special ... argument in a function definition.

Looping Functions

Looping on the Command Line

Writing for and while loops is useful when programming but not particularly easy when working interactively on the command line. Multi-line expressions with curly braces are just not that easy to sort through when working on the command line. R has some functions which implement looping in a compact form to make your life easier.

  • lapply(): Loop over a list and evaluate a function on each element

  • sapply(): Same as lapply but try to simplify the result

  • apply(): Apply a function over the margins of an array

  • tapply(): Apply a function over subsets of a vector

  • mapply(): Multivariate version of lapply

lapply()

The lapply() function does the following simple series of operations:

  1. it loops over a list, iterating over each element in that list
  2. it applies a function to each element of the list (a function that you specify)
  3. and returns a list (the l is for "list").

This function takes three arguments: (1) a list X; (2) a function (or the name of a function) FUN; (3) other arguments via its ... argument. If X is not a list, it will be coerced to a list using as.list().

lapply() Example 1

Here's an example of applying the mean() function to all elements of a list. If the original list has names, the the names will be preserved in the output.

x <- list(a = 1:5, b = rnorm(10))
lapply(x, mean)
## $a
## [1] 3
## 
## $b
## [1] 0.4584475

Notice that here we are passing the mean() function as an argument to the lapply() function. Functions in R can be used this way and can be passed back and forth as arguments just like any other object. When you pass a function to another function, you do not need to include the open and closed parentheses () like you do when you are calling a function.

lapply() Example 2

x <- list(a = 1:4, b = rnorm(10), c = rnorm(20, 1), d = rnorm(100, 
    5))
lapply(x, mean)
## $a
## [1] 2.5
## 
## $b
## [1] -0.2086744
## 
## $c
## [1] 0.7933276
## 
## $d
## [1] 4.964264

lapply() Example 3

x <- 1:4
lapply(x, runif)
## [[1]]
## [1] 0.03027641
## 
## [[2]]
## [1] 0.9230474 0.6971870
## 
## [[3]]
## [1] 0.1742712 0.2909109 0.8068311
## 
## [[4]]
## [1] 0.01373438 0.58143460 0.90845395 0.14748229

Now how about other arguments?

Here, the min = 0 and max = 10 arguments are passed down to runif() every time it gets called.

x <- 1:4
lapply(x, runif, min = 0, max = 10)
## [[1]]
## [1] 7.502668
## 
## [[2]]
## [1] 9.654888 2.876562
## 
## [[3]]
## [1] 3.0762490 9.4177522 0.3042502
## 
## [[4]]
## [1] 2.524403 5.582836 7.253145 3.342289

lapply() Example 4

Here I am creating a list that contains two matrices.

x <- list(a = matrix(1:4, 2, 2), b = matrix(1:6, 3, 2))
x
## $a
##      [,1] [,2]
## [1,]    1    3
## [2,]    2    4
## 
## $b
##      [,1] [,2]
## [1,]    1    4
## [2,]    2    5
## [3,]    3    6
  • How do you extract the first column of each matrix in the list?
  • Now you need an anonymous function for extracting the first column of each matrix.
lapply(x, function(elt) {
    elt[, 1]
})
## $a
## [1] 1 2
## 
## $b
## [1] 1 2 3

I can also define the function separately.

f <- function(elt) {
    elt[, 1]
}
lapply(x, f)
## $a
## [1] 1 2
## 
## $b
## [1] 1 2 3

sapply()

The sapply() function behaves similarly to lapply(); the only real difference is in the return value. sapply() will try to simplify the result of lapply() if possible. Essentially, sapply() calls lapply() on its input and then applies the following algorithm:

  • If the result is a list where every element is length 1, then a vector is returned

  • If the result is a list where every element is a vector of the same length (> 1), a matrix is returned.

  • If it can’t figure things out, a list is returned

Here's the result of calling lapply().

x <- list(a = 1:4, b = rnorm(10), c = rnorm(20, 1), d = rnorm(100, 
    5))
lapply(x, mean)
## $a
## [1] 2.5
## 
## $b
## [1] 0.2734051
## 
## $c
## [1] 1.287163
## 
## $d
## [1] 4.875645

Here's the result of calling sapply() on the same list.

sapply(x, mean)
##         a         b         c         d 
## 2.5000000 0.2734051 1.2871626 4.8756445

split()

The split() function takes a vector or other objects and splits it into groups determined by a factor or list of factors.

The arguments to split() are

str(split)
## function (x, f, drop = FALSE, ...)

where

  • x is a vector (or list) or data frame
  • f is a factor (or coerced to one) or a list of factors
  • drop indicates whether empty factors levels should be dropped

The combination of split() and a function like lapply() or sapply() is a common paradigm in R.

split() Example

Here we simulate some data and split it according to a factor variable. Note that we use the gl() function to "generate levels" in a factor variable.

x <- c(rnorm(10), runif(10), rnorm(10, 1))
f <- gl(3, 10)
split(x, f)
## $`1`
##  [1]  0.5213576 -0.4949237 -1.4574318 -1.2516105 -0.2620901 -0.6822597
##  [7] -0.2911013  0.3872132 -0.1806973 -0.8026308
## 
## $`2`
##  [1] 0.8886499 0.1562210 0.9131451 0.5814816 0.5589196 0.6086722 0.7820416
##  [8] 0.5149777 0.9720512 0.1489217
## 
## $`3`
##  [1]  0.7651050  0.5640002  1.5668331  1.4799608  0.1858316  2.7911229
##  [7]  0.9544162 -0.4530234  3.0252256  1.7288048

A common idiom is split followed by an lapply.

lapply(split(x, f), mean)
## $`1`
## [1] -0.4514174
## 
## $`2`
## [1] 0.6125082
## 
## $`3`
## [1] 1.260828

Splitting a Data Frame

library(datasets)
head(airquality)
##   Ozone Solar.R Wind Temp Month Day
## 1    41     190  7.4   67     5   1
## 2    36     118  8.0   72     5   2
## 3    12     149 12.6   74     5   3
## 4    18     313 11.5   62     5   4
## 5    NA      NA 14.3   56     5   5
## 6    28      NA 14.9   66     5   6

We can split the airquality data frame by the Month variable so that we have separate sub-data frames for each month.

s <- split(airquality, airquality$Month)
str(s)
## List of 5
##  $ 5:'data.frame':   31 obs. of  6 variables:
##   ..$ Ozone  : int [1:31] 41 36 12 18 NA 28 23 19 8 NA ...
##   ..$ Solar.R: int [1:31] 190 118 149 313 NA NA 299 99 19 194 ...
##   ..$ Wind   : num [1:31] 7.4 8 12.6 11.5 14.3 14.9 8.6 13.8 20.1 8.6 ...
##   ..$ Temp   : int [1:31] 67 72 74 62 56 66 65 59 61 69 ...
##   ..$ Month  : int [1:31] 5 5 5 5 5 5 5 5 5 5 ...
##   ..$ Day    : int [1:31] 1 2 3 4 5 6 7 8 9 10 ...
##  $ 6:'data.frame':   30 obs. of  6 variables:
##   ..$ Ozone  : int [1:30] NA NA NA NA NA NA 29 NA 71 39 ...
##   ..$ Solar.R: int [1:30] 286 287 242 186 220 264 127 273 291 323 ...
##   ..$ Wind   : num [1:30] 8.6 9.7 16.1 9.2 8.6 14.3 9.7 6.9 13.8 11.5 ...
##   ..$ Temp   : int [1:30] 78 74 67 84 85 79 82 87 90 87 ...
##   ..$ Month  : int [1:30] 6 6 6 6 6 6 6 6 6 6 ...
##   ..$ Day    : int [1:30] 1 2 3 4 5 6 7 8 9 10 ...
##  $ 7:'data.frame':   31 obs. of  6 variables:
##   ..$ Ozone  : int [1:31] 135 49 32 NA 64 40 77 97 97 85 ...
##   ..$ Solar.R: int [1:31] 269 248 236 101 175 314 276 267 272 175 ...
##   ..$ Wind   : num [1:31] 4.1 9.2 9.2 10.9 4.6 10.9 5.1 6.3 5.7 7.4 ...
##   ..$ Temp   : int [1:31] 84 85 81 84 83 83 88 92 92 89 ...
##   ..$ Month  : int [1:31] 7 7 7 7 7 7 7 7 7 7 ...
##   ..$ Day    : int [1:31] 1 2 3 4 5 6 7 8 9 10 ...
##  $ 8:'data.frame':   31 obs. of  6 variables:
##   ..$ Ozone  : int [1:31] 39 9 16 78 35 66 122 89 110 NA ...
##   ..$ Solar.R: int [1:31] 83 24 77 NA NA NA 255 229 207 222 ...
##   ..$ Wind   : num [1:31] 6.9 13.8 7.4 6.9 7.4 4.6 4 10.3 8 8.6 ...
##   ..$ Temp   : int [1:31] 81 81 82 86 85 87 89 90 90 92 ...
##   ..$ Month  : int [1:31] 8 8 8 8 8 8 8 8 8 8 ...
##   ..$ Day    : int [1:31] 1 2 3 4 5 6 7 8 9 10 ...
##  $ 9:'data.frame':   30 obs. of  6 variables:
##   ..$ Ozone  : int [1:30] 96 78 73 91 47 32 20 23 21 24 ...
##   ..$ Solar.R: int [1:30] 167 197 183 189 95 92 252 220 230 259 ...
##   ..$ Wind   : num [1:30] 6.9 5.1 2.8 4.6 7.4 15.5 10.9 10.3 10.9 9.7 ...
##   ..$ Temp   : int [1:30] 91 92 93 93 87 84 80 78 75 73 ...
##   ..$ Month  : int [1:30] 9 9 9 9 9 9 9 9 9 9 ...
##   ..$ Day    : int [1:30] 1 2 3 4 5 6 7 8 9 10 ...

Then we can take the column means for Ozone, Solar.R, and Wind for each sub-data frame.

lapply(s, function(x) {
    colMeans(x[, c("Ozone", "Solar.R", "Wind")], na.rm = TRUE)
})
## $`5`
##     Ozone   Solar.R      Wind 
##  23.61538 181.29630  11.62258 
## 
## $`6`
##     Ozone   Solar.R      Wind 
##  29.44444 190.16667  10.26667 
## 
## $`7`
##      Ozone    Solar.R       Wind 
##  59.115385 216.483871   8.941935 
## 
## $`8`
##      Ozone    Solar.R       Wind 
##  59.961538 171.857143   8.793548 
## 
## $`9`
##     Ozone   Solar.R      Wind 
##  31.44828 167.43333  10.18000

Using sapply() might be better here for a more readable output.

sapply(s, function(x) {
    colMeans(x[, c("Ozone", "Solar.R", "Wind")], na.rm = TRUE)
})
##                 5         6          7          8         9
## Ozone    23.61538  29.44444  59.115385  59.961538  31.44828
## Solar.R 181.29630 190.16667 216.483871 171.857143 167.43333
## Wind     11.62258  10.26667   8.941935   8.793548  10.18000

tapply()

tapply() is used to apply a function over subsets of a vector. It can be thought of as a combination of split() and sapply() for vectors only.

str(tapply)
## function (X, INDEX, FUN = NULL, ..., default = NA, simplify = TRUE)

The arguments to tapply() are as follows:

  • X is a vector
  • INDEX is a factor or a list of factors (or else they are coerced to factors)
  • FUN is a function to be applied
  • … contains other arguments to be passed FUN
  • simplify, should we simplify the result?

tapply() Example

Given a vector of numbers, one simple operation is to take group means.

## Simulate some data
x <- c(rnorm(10), runif(10), rnorm(10, 1))
## Define some groups with a factor variable
f <- gl(3, 10)
f
##  [1] 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3
## Levels: 1 2 3
tapply(x, f, mean)
##           1           2           3 
## -0.08801145  0.57832382  0.61165490

It is equivalent to:

sapply(split(x, f), mean)
##           1           2           3 
## -0.08801145  0.57832382  0.61165490

apply()

  • Used to a evaluate a function over the margins of an array.
  • Often used to apply a function to the rows or columns of a matrix.
  • Using apply() is not really faster than writing a loop, but it works in one line and is highly compact.
str(apply)
## function (X, MARGIN, FUN, ...)

The arguments to apply() are

  • X is an array
  • MARGIN is an integer vector indicating which margins should be “retained”.
  • FUN is a function to be applied
  • ... is for other arguments to be passed to FUN

apply() Example

Here I create a 20 by 10 matrix of Normal random numbers. I then compute the mean of each column.

x <- matrix(rnorm(200), 20, 10)
apply(x, 2, mean)  ## Take the mean of each column
##  [1] -0.003091311 -0.121190034  0.041603721 -0.242930732  0.101452141
##  [6] -0.242144753 -0.160848546 -0.025957193  0.425527810  0.275249740

I can also compute the sum of each row.

apply(x, 1, sum)  ## Take the mean of each row
##  [1]  5.87282005 -2.12191976 -0.72172661 -0.04755029 -0.02887617
##  [6]  1.85687518 -5.53461566 -3.38001553  3.82259527  2.24135008
## [11]  2.85755848 -3.99765124  1.07589800  1.66616429  2.88450445
## [16] -5.14690929 -0.82670841  2.93204919  1.80638471 -4.25680989
  • Note that in both calls to apply(), the return value was a vector of numbers.
  • The MARGIN argument essentially indicates to apply() which dimension of the array you want to preserve or retain. So when taking the mean of each column, I specify
apply(x, 2, mean)

Col/Row Sums and Means

For the special case of column/row sums and column/row means of matrices, we have some useful shortcuts.

  • rowSums = apply(x, 1, sum)
  • rowMeans = apply(x, 1, mean)
  • colSums = apply(x, 2, sum)
  • colMeans = apply(x, 2, mean)

The shortcut functions are heavily optimized and hence are much faster, but you probably won’t notice unless you’re using a large matrix. Another nice aspect of these functions is that they are a bit more descriptive. It's arguably more clear to write colMeans(x) in your code than apply(x, 2, mean).

Other Ways to Apply

You can do more than take sums and means with the apply() function. For example, you can compute quantiles of the rows of a matrix using the quantile() function.

x <- matrix(rnorm(200), 20, 10)
## Get row quantiles
apply(x, 1, quantile, probs = c(0.25, 0.75))
##           [,1]       [,2]       [,3]      [,4]       [,5]       [,6]
## 25% -0.3170086 -0.2744589 -0.2732093 -1.282734 -0.6017231 -0.4935691
## 75%  0.9584784  0.8506353  0.3354259 -0.322540  0.4121794  0.6357492
##           [,7]       [,8]       [,9]      [,10]      [,11]      [,12]
## 25% -0.9245659 -0.2932466 -0.3625397 -0.4836953 -1.6742613 -0.4748696
## 75%  0.1728844  0.7594619  0.4205175  0.8818359  0.7489506  0.5036317
##          [,13]      [,14]      [,15]     [,16]      [,17]      [,18]
## 25% -0.2073411 -0.6966284 -1.4482386 0.2716661 -0.3652313 -0.6475931
## 75%  0.8181118  0.8165583  0.2464965 0.8360142  0.4953018  0.7935044
##          [,19]      [,20]
## 25% -0.6373888 -0.3044617
## 75%  0.2549292  0.9213822

Notice that I had to pass the probs = c(0.25, 0.75) argument to quantile() via the ... argument to apply().

mapply()

The mapply() function is a multivariate apply of sorts which applies a function in parallel over a set of arguments. Recall that lapply() and friends only iterate over a single R object. What if you want to iterate over multiple R objects in parallel? This is what mapply() is for.

str(mapply)
## function (FUN, ..., MoreArgs = NULL, SIMPLIFY = TRUE, USE.NAMES = TRUE)

The arguments to mapply() are

  • FUN is a function to apply
  • ... contains R objects to apply over
  • MoreArgs is a list of other arguments to FUN.
  • SIMPLIFY indicates whether the result should be simplified

The mapply() function has a different argument order from lapply() because the function to apply comes first rather than the object to iterate over. The R objects over which we apply the function are given in the ... argument because we can apply over an arbitrary number of R objects.

mapply() Example

For example, the following is tedious to type

list(rep(1, 4), rep(2, 3), rep(3, 2), rep(4, 1))

With mapply(), instead we can do

mapply(rep, 1:4, 4:1)
## [[1]]
## [1] 1 1 1 1
## 
## [[2]]
## [1] 2 2 2
## 
## [[3]]
## [1] 3 3
## 
## [[4]]
## [1] 4

This passes the sequence 1:4 to the first argument of rep() and the sequence 4:1 to the second argument.

Here's another example for simulating randon Normal variables.

noise <- function(n, mean, sd) {
    rnorm(n, mean, sd)
}
## Simulate 5 randon numbers
noise(5, 1, 2)
## [1]  1.788075  3.714255 -1.153818 -0.490320  1.908989

Here we can use mapply() to pass the sequence 1:5 separately to the noise() function so that we can get 5 sets of random numbers, each with a different length and mean.

x <- mapply(noise, 1000, 1:5, 1:5)
apply(x, 2, mean)
## [1] 1.008757 1.901239 3.046719 3.892496 4.922481

The above call to mapply() is the same as

list(noise(1000, 1, 1), noise(1000, 2, 2), noise(1000, 3, 3), 
    noise(1000, 4, 4), noise(1000, 5, 5))
## [[1]]
##    [1]  1.955302252  2.959080308  1.002897509 -0.619376275  0.755031481
##    [6]  1.247176161  1.139343055  0.956316783  1.999033496  2.007217922
##   [11]  1.907202239  2.515733734  0.568705723  1.037764349  1.463947317
##   [16] -0.562678416  0.530878336  0.698281784  0.813450374 -0.376368757
##   [21]  1.762426041  2.009782015  1.566885821  1.297978828 -0.358044777
##   [26]  1.799450685  1.180235900  1.369676766  0.560836653  0.709053535
##   [31]  0.894317485 -0.487062606  0.977079278 -0.288412905  1.941884617
##   [36]  1.813371867  2.893191258  0.666378998  0.860794265  2.507273808
##   [41] -0.131754115  1.698205510  0.284518407  2.057127029 -0.341743406
##   [46] -0.104689686  1.807785051  2.967363459  0.624099916  2.439206482
##   [51]  0.039300528  0.640395553  0.812767239  0.333379054  2.032925705
##   [56]  0.543225069  0.780512975  0.073612458  0.994054943 -0.105819107
##   [61] -1.294198628 -0.136701291  1.481351486  0.956254469  0.807420280
##   [66]  0.089639104  0.402769765 -0.001309240  0.591956643  2.028195930
##   [71]  1.212541607  1.939494616  1.179700104  1.533248319 -0.790666484
##   [76]  2.459636013  2.315306286  1.161278300 -0.050314743 -0.152412727
##   [81]  1.517029350  1.775076008 -0.087907192 -0.468461708  0.189496731
##   [86]  1.511088282  0.388231795  1.382248035  0.555993100  2.465056900
##   [91]  1.040933649  1.521867598  1.103172259  1.360169111  0.519167753
##   [96]  0.941802625  2.219611443  1.124194952  1.899478437  2.683373577
##  [101]  2.828082108  0.705631742  0.169909497  0.030087209  2.174638831
##  [106]  1.587533670  1.220248553 -0.403001412  4.020572766  1.502244961
##  [111]  0.217650529  1.143285142  1.743664382  0.021626396  1.065347298
##  [116] -1.311855901  1.680834449  2.752660975  0.710269579 -0.125084412
##  [121]  0.703076145  0.252047097  0.929062952  1.055982970  3.095123080
##  [126]  0.883715567  0.305355061 -0.105191215  0.035014366  0.590540592
##  [131]  0.942612479  0.855909683  1.404057978  0.218306442  0.877912721
##  [136]  0.923666471 -0.118379631  1.434704377  1.092584710  0.439581614
##  [141]  0.706106273  1.431611127  1.989959835  2.113997800  2.005985517
##  [146]  1.238383266  1.548127891  0.257784679 -0.025883497  1.532490710
##  [151]  0.112290626  1.199379038 -0.877036558  1.470128053  0.668684625
##  [156]  3.599719894  0.453279501  1.029429260  1.348491068 -1.196485790
##  [161]  1.638292546  1.172614985  1.198878635  2.972526801  1.083990849
##  [166] -0.126119885 -0.094169216  0.764844287  0.600829337  2.941671329
##  [171]  2.947426790  0.827901751  3.566843805  0.115375306  1.770720039
##  [176]  1.522405799  0.744900291  0.097041785  1.872323654  0.740838313
##  [181]  1.792337774  1.297025697  1.488711099  0.117211294 -0.130532884
##  [186]  0.095245703  2.329663614  0.679869500  1.396062829 -0.001565089
##  [191]  0.642259725  0.421377810  1.764338723  0.659822185  0.383588940
##  [196]  1.079264938  0.743434351  0.120598614  1.345147859  0.387118738
##  [201]  0.135614719  1.413325820  0.528099251  1.911301241  1.225218532
##  [206]  0.473076530  2.079978488  1.493439348  2.177776093  1.212341723
##  [211]  1.473181877  1.873185100  1.437455661  2.050456175  0.026319993
##  [216]  0.798555495  1.693104430  0.333386062  1.284931712  0.971178987
##  [221]  0.310535477  1.707205804  0.665354007  0.695620928  0.162496808
##  [226]  2.327153993  1.044290430  1.654680193 -0.550902361  2.322449957
##  [231]  0.196581380  1.806212498 -0.381891882  1.248167301  1.360095612
##  [236]  0.092932271  2.591803439  1.394059942  1.947097046  0.697971205
##  [241]  0.593751297 -0.539132268  2.125972655  1.277760437  2.912691031
##  [246]  1.134276527  1.241298367  2.744218101  0.131025135  0.377182114
##  [251] -0.221596832  0.141852499  2.338735200  0.550056505  1.334720772
##  [256]  1.926276992  2.492337775  2.578180107  1.981350368  1.015507630
##  [261]  0.435052174 -0.422334742  1.666511431  1.789839811  0.320367088
##  [266]  2.105201998  0.417209345  0.917045389  1.396386207  0.484592085
##  [271]  0.869275389  0.231089370  1.104408755  2.073248840  2.764373765
##  [276]  1.631864175  2.474007615  2.080721701  2.290480744  1.620227059
##  [281] -0.468932625  0.867823999 -0.375534824  0.660907316  1.849628499
##  [286]  0.732876691  0.896497797  0.254437147 -0.167867387  1.690027882
##  [291]  1.166910261  0.380410727  2.255612622  0.403082365  1.335714982
##  [296]  1.470211898  1.950688433  2.201924397 -0.233632088  1.038703116
##  [301]  0.182034876  0.798245917  1.119917478  1.058133954  1.685758923
##  [306]  1.331793058  0.892071386  0.787753671  0.140889291  0.741885208
##  [311]  0.271427247  2.569952399  1.413478710  2.293195005  2.211974052
##  [316] -0.241305343  2.565294828  0.149093006  1.266073974  1.791502605
##  [321]  0.231398873  0.415023378  1.501830969  0.630589568  0.791258649
##  [326]  1.547347534 -0.566199552  0.086529580  1.163649493  1.031724064
##  [331]  0.141345008  1.687022492  2.088889464  1.754096197  1.261405891
##  [336]  1.381529499  0.618970679  1.895241608  1.566158648  0.758254113
##  [341]  0.932926986  1.367972401  1.302894828  1.176236854  1.465753988
##  [346] -1.038855933  1.646838007  1.795848674  0.405974639  2.037804656
##  [351]  1.971084047  1.948415425  1.061039921  0.883734725  0.420573736
##  [356]  1.611091366 -0.325186822  3.496598555  0.400462784  1.794998617
##  [361] -0.813388633  0.691166951  1.985535698  0.961151339  0.301480287
##  [366] -0.390030630  2.119013929  0.412114498  1.497942787  2.483232850
##  [371]  1.246197086  2.069333436  0.903617559  1.744516076 -0.395293150
##  [376]  2.681088553  1.294191798  1.601589857 -0.881278794  1.798160737
##  [381]  0.872962466  0.272361538  1.587744650  0.635351007  2.652595124
##  [386]  0.337511033  0.519856471  1.759343961  0.557395106  2.539299290
##  [391]  0.708242529  1.344375345  1.527211467  0.950262234  0.839802539
##  [396]  1.860192225  2.088632282  1.161980673  1.516993937  2.057863271
##  [401] -0.491059903  1.364745083  0.902618976  0.950021827 -0.976651578
##  [406]  2.108855755  0.224476325 -0.235793994  1.387621185  1.204685133
##  [411]  0.839408827  1.936313690  0.832058087  0.187806627  0.329993188
##  [416]  1.179622141  0.951517147 -0.110058207  0.865033162 -0.522863080
##  [421]  2.168196981  0.407227002  0.222310211  1.334318465  1.214156830
##  [426]  0.841155222 -0.893760096 -0.059445714  1.722909087  2.850998949
##  [431]  0.212445383 -0.273505792  2.078226728  0.893508302  0.269106678
##  [436]  2.261841963  2.258135198  1.316722054  1.264343643 -0.384810620
##  [441]  1.351168962  2.293922179  1.339327392  2.451581133  1.935693615
##  [446]  1.006746503  2.467137038  0.445736865 -0.014919700  1.766833068
##  [451] -0.426547315 -0.030113741 -0.204602310  1.523403278  1.843609909
##  [456]  2.688213043 -0.405605509  1.660786762  1.832085173 -0.162075733
##  [461]  0.575922044  1.504100596  2.247513441  1.444986061  1.837619875
##  [466]  1.082012052  2.425921299  1.405493613  1.355826604  2.839994759
##  [471]  1.712590953  1.727529545  2.549590141  3.839554775  0.288793054
##  [476]  1.159722172  2.045162445  0.581732178  0.762829674  0.100900736
##  [481]  0.325646811  0.093657199 -1.076488474  1.753048724  1.059468778
##  [486] -0.078870236  0.179890976  0.947485016  1.721036507  0.901286575
##  [491] -0.104292042 -0.359128870  0.759462222 -0.162999107 -0.497917065
##  [496]  1.231209705  1.838289973  0.498372470 -0.687020170 -0.283289929
##  [501]  1.071095015  0.522139489  1.864358878  1.145525913  0.385120099
##  [506]  0.404453792  1.851996676  1.350178150  0.879637111  0.998311343
##  [511]  1.292010469 -0.579359163  1.556983387 -0.795951641  1.673354980
##  [516]  2.381162920  0.006109894  0.597637445  3.291902579  0.884246068
##  [521]  1.651095843  1.619243794  0.915400191  0.352979695  1.415867298
##  [526]  0.716662121  2.153819472  1.955151831  1.742733252  1.291522990
##  [531] -0.422797661  1.965809126  2.201718200  1.234187512  0.390653216
##  [536]  2.655169051  1.211997070  0.139503941 -0.912600552  2.076408188
##  [541]  0.890933315  2.580546776  1.321979872 -0.618791061 -0.460960113
##  [546] -0.468212571  1.869364886  1.545307170 -0.143476026  0.481803074
##  [551]  1.850970378  3.152900038  1.002608106  2.472027573  1.292799149
##  [556]  1.539812504  2.329204946  1.250873121  2.556816440  1.512000391
##  [561]  1.124931233 -0.181366180  1.137904910  0.971207748  1.744148618
##  [566]  1.020527159  1.313162108  0.685366203  1.316822646  0.795551188
##  [571]  1.109792116  1.203220231  1.257714671  1.001253578 -0.097900387
##  [576]  0.577028013  0.629829649  0.454161395  1.342553624 -0.551491293
##  [581]  0.439950030  1.322610234  1.029174939  1.112434427 -0.237840747
##  [586]  0.964911457 -1.075024895  0.343908509  0.479204981  0.357943680
##  [591]  1.077195532  1.336940691  0.950371572  0.703427208  0.302258852
##  [596]  2.403818162 -1.314174550  0.893944063 -0.636960787  0.718056960
##  [601]  1.643428006  2.582070607  1.448696455  0.588185661  0.115584770
##  [606]  0.541340738 -1.426525534  2.039837611  0.820431897 -1.406734470
##  [611]  2.752582543 -0.700947401  1.882160577  1.671815835  1.160730092
##  [616]  0.375734380  0.814375142  0.689768931  1.990595837 -0.049133398
##  [621] -0.817016751 -0.483594588  0.822108099  0.266641999  1.382434634
##  [626]  1.365397407  1.301364375  1.519338812  0.234263730  0.962418784
##  [631]  0.432376160 -0.372400072  0.973094987  1.602391713 -0.076364622
##  [636]  0.083730734 -1.394521081  0.145561224  1.027769113 -0.318158947
##  [641]  0.761692990  0.499517206  0.259526110  1.058772250  1.547816520
##  [646]  1.058230277  0.692925286  1.463544505  2.263484315  1.550748495
##  [651]  1.254907393  1.190536471  1.614834263  1.724552067  1.390585266
##  [656]  0.515879182  0.390242438  1.605257550 -0.170532968  2.276405217
##  [661]  1.075046776 -0.717926528  2.714909476  2.163302325  0.176588752
##  [666]  3.344914690  1.911256736  1.147336285  0.480086496  2.040685038
##  [671]  1.585167173  1.501519559  1.166226906  0.823778066  0.644044743
##  [676]  0.583254773  2.514066799  0.067666262  2.051058088  0.197676290
##  [681]  1.356276808  2.291200853  0.225289603  0.034506959  1.505697082
##  [686]  1.222883602  2.471808120  1.390770247  0.490847781  1.580632703
##  [691] -0.010950091  1.223212667  0.591436809  2.234460906  2.012419823
##  [696] -0.317137349  1.022585698  2.514167388  1.459988850  0.491714554
##  [701]  1.311319918  0.705884649  1.985723741  1.273886678  0.605957098
##  [706]  1.980833803  1.423708568  2.901300970 -0.504377422  2.146117971
##  [711]  1.742704993  0.743248709  0.581268798  0.182118871  0.690574636
##  [716]  2.210961072  1.381888113  0.805893957  0.211581292 -0.670013572
##  [721]  0.019810146  0.015324122  0.998842469 -0.070025600  1.487460001
##  [726]  1.999806570  0.476380810  2.349202720  1.056708254  0.975569522
##  [731]  0.098695123  0.447585592  0.115517150  2.763328312  0.448067428
##  [736]  0.489279968  0.264338988  1.219528122  1.842558646  2.179144111
##  [741]  0.900780579  2.315888258  1.943961819  1.567443755  0.740123207
##  [746]  0.527328060  1.701850622  1.402535580 -0.036457634  1.248031622
##  [751] -0.093901627  1.382590982 -1.266554022  0.848779108 -0.446145189
##  [756]  0.672662058  1.234650494  1.710291419  1.330775267  1.400682399
##  [761]  0.368502353  1.527917379  0.343613429  0.173334191  0.741967490
##  [766]  0.390585739  0.710332530 -0.322643466  1.726334210  1.469320920
##  [771]  0.796365435  0.830894512  2.245627234  1.187274554  0.162870435
##  [776]  1.920231965  1.700250431  0.559520247  0.958395156  1.167761648
##  [781]  1.027247467  2.684665834  0.603415017  1.818942026 -0.702055356
##  [786]  1.942324867  2.076794292  0.754506068  0.067573139  0.727401476
##  [791]  1.368136220  1.410937830  0.869129605  1.242828940  1.561651646
##  [796]  0.084306632  1.007855328  2.687387593  0.831228992  0.855222904
##  [801] -0.737174659  0.416005151  0.747225694  2.055921708  1.974979005
##  [806]  0.495249523  0.247261661  0.545910230  3.319267270  1.559157570
##  [811]  0.215727807  1.629468133 -1.739773400  1.165485173  1.299341900
##  [816]  1.283674609  0.927702029  1.654443154  2.130987866  1.063830054
##  [821]  1.892117387  1.985391690  1.155592659  0.130535940  1.992025020
##  [826]  1.286658922 -0.213171263  0.535061323  2.544563230  1.557588879
##  [831]  0.207240954 -0.105978359  1.274213049  0.689433927  1.484933551
##  [836] -0.976205986 -0.876703577  1.025546953  1.204769280  1.199345845
##  [841]  1.730123976 -0.272495345  1.247894844  0.903311194  1.007961648
##  [846]  2.566920825  1.736785452  1.035091244 -0.834322236  0.912925317
##  [851]  0.634080838 -0.025985541 -0.043939884  0.552958863  0.691395796
##  [856]  1.780122640  1.737041054  1.624783859  2.341886120  0.050897420
##  [861]  1.460210913  0.761247451  2.115467260  2.823957092  1.216333813
##  [866] -0.596139158 -0.091078265  1.965493009  1.795895794  2.988421753
##  [871]  0.697144258  1.015385362 -0.530490491  0.878168209  1.989284941
##  [876]  2.026204176  0.736870677  2.160520162  1.221989449  0.848204474
##  [881] -0.300238220  1.955435127  0.795104338  0.302098939  0.161020126
##  [886]  1.592821742  0.339416814  1.180758816 -0.147180512  0.044044257
##  [891]  2.385676433 -0.711199392  1.726604257  1.214192250  0.786902364
##  [896]  0.462002201  0.959094764  1.612294762  1.843288010  2.014246631
##  [901] -2.185369617  2.144613608  0.451358517  0.886368840 -1.085496297
##  [906]  0.654052933  1.563278663  0.914821707  3.311886112  0.846984688
##  [911]  1.676379918  2.547531319 -1.119131169  0.967875973  1.447655710
##  [916] -1.310825569  2.347954029  0.322237131  0.023424296  0.368551684
##  [921]  0.276702467  1.582592062 -0.446603903  0.442789049  0.799357466
##  [926]  1.627522315  1.320407446  0.675516950  0.719147936  0.412877428
##  [931] -0.049444659  1.974641633  0.167681178  1.913248361  1.848872148
##  [936]  1.610590603  1.335528070  1.405069140  1.030334912  0.648820997
##  [941] -0.834725407  0.616961062  0.809430891  2.394613505  0.866051917
##  [946]  1.276073526 -1.109726271  2.012570767  0.571947850  2.001173318
##  [951] -0.247735087  0.871918998  1.761059772  2.041566024  0.170523048
##  [956]  0.868746537  1.237102241  2.244467979  0.444272681  0.610901370
##  [961]  1.964576797  1.717628938 -0.837530186  0.984066909 -0.097358641
##  [966]  2.780768738  1.192798036  1.409338524  1.700005830  2.150900723
##  [971]  2.237624487 -0.728382501 -1.054709168 -0.078528241  0.336122367
##  [976] -0.112095122  0.539874303  0.589362239  0.976124353  1.752779848
##  [981]  1.452780600  1.241383416  2.645474355  0.364330121  2.361239821
##  [986]  1.152334096  0.999806790  2.369419893  2.429891058  0.527585727
##  [991] -0.605926725  0.176062990 -0.568796591  0.919782846  2.657762495
##  [996]  2.680944548  0.867796209  0.707596313 -0.045052977  1.846242596
## 
## [[2]]
##    [1]  2.543247724  0.834072001  0.750577848 -0.725372054  4.288489341
##    [6]  1.977509151  1.187598862  4.963017751 -0.314150644  1.576310020
##   [11]  4.283295252  3.680683836  3.726483995  1.551142781  5.191555634
##   [16]  4.592950991 -0.105059555  0.979138750  2.013211368  1.411823724
##   [21]  3.876635799 -0.996068727  3.603250057  1.353858373  1.832477634
##   [26] -3.342983128  5.389032378  1.012140456 -0.571260536  2.887389763
##   [31]  2.720239237  4.400573827  2.787765078 -1.790444378  3.153796185
##   [36]  1.245138683  0.473983726  2.593561139  3.232515883  5.371587052
##   [41]  3.891587420  1.495200020  1.742332166  4.531708648  2.485920587
##   [46]  3.231673896 -4.286691166  2.682846614  0.394196306  0.909281453
##   [51]  5.481808470  2.977150938  2.766145849  0.672559702  2.147136489
##   [56]  2.743771678  1.759025657  3.704190744  2.688550670  1.564871492
##   [61]  2.846761419 -0.587295321  3.028396212  3.704350145  2.876018441
##   [66]  2.385980814  2.927896014  5.262130787  4.373010304  5.842146936
##   [71]  2.237365228 -0.609274461  3.353440153  1.756323183  4.832579400
##   [76] -0.667674260  2.315445300  4.275994692  0.886012123  2.965088116
##   [81]  1.617372889  1.168602626  4.746012291  3.780685336  1.716193728
##   [86]  2.940595814  2.160334655  3.570680996  1.711623016 -1.830152585
##   [91]  4.494105152  0.961597344 -0.953502598  1.842278222  2.902119110
##   [96] -2.424579436  3.093325094  3.502153776 -1.082268249  3.551228587
##  [101] -0.186006863  1.064930162  1.269394119  2.673691437 -0.623741959
##  [106]  3.021308971  3.335249266 -1.579018784  2.229280614  2.448193955
##  [111] -0.442256328  0.808104681  3.478615852  0.862727376  2.348848780
##  [116] -1.244671437 -0.728328153 -0.337893703  0.532650528 -0.547644981
##  [121]  1.823488720  6.645680586  1.323336251  1.698701319  4.787797677
##  [126]  0.142063510  3.370494092  2.269685003 -1.101402768 -1.590675329
##  [131]  3.862948430  1.498289569  4.638070212  1.646898500  1.913457202
##  [136] -0.659764620  0.569616203  4.006466066  1.941632876  3.961556838
##  [141]  1.837023450  4.919146300  3.276351944  0.266645852  3.546220585
##  [146]  4.956054789  5.735735586  0.696576146  3.680394000  0.159257132
##  [151]  2.607132973 -3.279019713  1.518249585  1.205449224  2.709472108
##  [156]  2.501007760  2.328254982  1.008287802  4.511530814  1.231021209
##  [161]  3.029229142  0.435093563  3.901656525  1.006293538 -0.039241974
##  [166]  1.660356066 -0.445624485  1.961834301  2.005379157  1.060648045
##  [171]  0.291886495 -1.459427025 -0.118660510  3.607807722  2.905412132
##  [176]  1.870902643  1.886840622  1.209114316 -0.008542019 -1.048581676
##  [181]  1.750936961  4.497552020  3.270583629 -1.940201124  0.876936351
##  [186]  3.042983194  2.810566082  3.667562491  1.992767241  5.294997453
##  [191]  2.184001146  3.321166079  1.671225199  3.015712491  3.932118919
##  [196]  4.403508294  1.603160485 -0.551398583  0.063083551  3.220161935
##  [201]  0.385792486  1.862327467 -4.117876614  5.217124860  1.228873300
##  [206]  1.267523943  3.647492098 -0.930164567  0.298897728  2.602393211
##  [211]  0.129466639  2.620168620  5.572606640  2.128416621  2.820423496
##  [216]  0.295455924  2.870986457  4.634878122 -2.304326487  2.370872970
##  [221]  3.697701435  3.028497618  3.741638958 -1.695829394 -0.720450162
##  [226]  2.804225528  2.385607731  2.140360741  2.027461071  3.390835856
##  [231]  2.759579966  2.120177395  1.797448859  2.853322123 -0.963454126
##  [236]  2.685544383  3.087545928  1.973121029  2.025609145  0.558158522
##  [241]  6.166273161 -0.906126691  0.727051470  2.014292303  0.567931818
##  [246]  2.020883013  0.889051659 -0.674477527 -0.388241251  2.961489195
##  [251]  3.249684211 -3.038462445  2.269557314  2.406213086  2.561131320
##  [256]  1.442742336  3.055412770  2.427266805  1.244072467 -0.672026878
##  [261]  4.057235371  0.709798863  2.557846796  1.410124860  2.286224129
##  [266]  2.168622707  3.202241202  3.750628311  1.641605734  1.033124712
##  [271]  2.900025167  2.721586699  3.231090446  4.809154575  1.298670474
##  [276]  2.623116705 -2.430056308  3.391112518  0.710308098  0.578335951
##  [281]  2.268382485  2.539566058  3.406138711 -0.431528900  4.373351569
##  [286]  3.399393614  0.687036087  1.446908155  4.895402462  0.217427537
##  [291]  1.816010738  2.927124759 -3.005344438  3.185141194  3.308949316
##  [296]  0.542865696  0.484084641  0.209438218  2.532275980  1.285872896
##  [301]  2.032720079  2.676943587  0.437954977 -0.480440309  3.753483261
##  [306]  2.175722399  2.284140684  1.922709318  0.535188968 -2.065583880
##  [311]  2.792525511  1.097182736  1.578790219  2.198145038  4.970317884
##  [316]  2.175011157  4.867772995  1.474090003  1.256678713 -1.050957738
##  [321] -0.974419758 -1.810774419  1.150031182  1.999195195  2.519099869
##  [326]  5.754306717  2.401585951  0.982061720  1.797389492  3.822022515
##  [331]  4.125829791  0.480579249  4.100271627 -0.046837543  1.304546555
##  [336] -0.666976081 -3.310568487  2.377267382 -0.422659444  2.540539636
##  [341]  1.693077297 -0.359022527  2.833887096  4.423752884  4.140108942
##  [346]  0.896231965 -1.877681845  0.363192836  1.797767626  1.516708668
##  [351]  0.526554348 -0.486592507  5.375771052  5.078082775  0.196003145
##  [356]  1.566224066  5.019020583  1.449177601  0.790617719 -1.677137381
##  [361]  3.506332179  1.540347299  1.343950771 -0.002535337  2.854494237
##  [366] -0.353094361  2.512755048  3.480804077  4.010133670 -1.668345099
##  [371]  0.182631283  1.859494328  3.134286124  1.741153641  5.662336425
##  [376]  6.920014901  7.325275302  4.108358096 -1.409542582  0.143995828
##  [381]  0.469421101 -1.735290979  2.939796884  2.750353969  0.361450432
##  [386]  2.798045316  1.595702242  3.323170717  1.845362985 -0.223567059
##  [391]  4.612506848  0.305031680  5.412801925  0.052934132  1.937868869
##  [396]  0.590210337  2.660153455  0.952555545 -0.090461031  0.787689069
##  [401]  3.597497161  2.074895343  3.088875422  2.039294766  4.769661968
##  [406]  4.350710999  2.859260979  4.772839375  4.026866150  2.388287394
##  [411]  3.727331351 -0.842032482  1.410029629  2.531727242  2.813192874
##  [416]  1.200053280  2.902598609  0.217356266  2.528278115  3.031916335
##  [421]  2.626819833  3.899233941  2.388271889  3.789498156  2.587706625
##  [426]  3.338074418  0.506275663  3.682199359 -0.110409479 -0.418157916
##  [431]  3.381900729  3.522474942  3.171695870  3.434294445  2.380600491
##  [436]  3.612108653  2.067787892  2.551132146  6.454773601  0.328035786
##  [441]  4.577302984  1.809444660 -0.921015241  3.456282315  2.129443252
##  [446]  0.476115318  1.127214650  3.405492872  4.042595164  1.310401673
##  [451]  2.469149136 -0.687081714  0.849280254  2.079501645  1.264606116
##  [456]  4.909155597  2.699765659  5.402149226  0.830425836  6.929336836
##  [461]  0.882115140  1.691975209  1.009917117  2.259064196  3.312547700
##  [466] -1.620971376  3.287291314  3.204561711  1.221381529 -0.487727063
##  [471] -0.501742067  0.067967122  1.710147144  2.821044940  3.288949291
##  [476]  1.050206495  1.081579665  2.776174550 -0.514502555  3.629221693
##  [481]  2.984374845 -1.103247767  2.102595599  2.084152595  1.973120230
##  [486]  1.687702637  0.807952177 -0.327244152  5.028808161  1.112289726
##  [491]  0.948869347  1.520770284  3.947221243  1.641987078  1.504703684
##  [496]  2.484693723  0.887320453  1.123497439  0.823768110  6.472406095
##  [501]  0.977043124 -1.495453217  1.291963374  3.456093804  2.303214075
##  [506]  0.115803644  2.356783225  1.333833334  1.466543264  3.323215023
##  [511]  2.006736210 -0.626379614 -1.371813697 -0.835512759 -2.414155914
##  [516]  2.883486497 -0.341206744  1.500418213 -2.147691471  6.184342399
##  [521] -2.163703600 -0.267784256  2.998908978  2.258285784 -2.591385664
##  [526]  2.105368208 -0.198882332  0.836510810  1.005490877  2.869459936
##  [531]  4.423842078  1.318042760  3.919137555  3.879653406  1.735810415
##  [536]  2.053231892  6.799638123  2.799070426  1.780322633 -0.705208375
##  [541]  0.026297713  2.859602492  4.291493150  2.033232081  4.806298598
##  [546]  3.542742397  5.079581433  3.077268748  2.738366414  3.414632853
##  [551]  3.872024263  3.054153689 -2.032333343  1.478722145  3.356783523
##  [556] -1.387532105  2.739326149  2.815685789  2.577173417  0.082489641
##  [561]  3.621388289  1.047260139  0.747228231  7.493991619  2.679599307
##  [566] -2.007508518  3.628905223  1.017113637 -1.950108074 -0.532718274
##  [571]  2.311028950  1.772417885  1.713356610  4.024193455  4.062993491
##  [576]  4.630086599  0.616265612  0.489568508  4.560953069  0.411628907
##  [581]  2.745987832 -3.884363924  1.779223566  2.636149852  2.100344724
##  [586]  2.674251448  1.885723477 -0.445363554 -0.395845808  1.787375558
##  [591]  4.179941731 -1.870330854  3.349273311 -1.426272672  2.150994931
##  [596]  1.961335834  2.135898374  1.884905625  3.460373232  6.990912257
##  [601]  5.488450173  2.121929589  0.485151090  1.943040420  0.242552808
##  [606]  4.819308437  1.139511411  2.721622210  3.090849493  2.876423819
##  [611]  2.206990306  0.672974227  0.920358133  1.205905780  3.328342213
##  [616] -0.137553822  3.236910452  3.629036755  2.980090955  3.468234252
##  [621]  4.596319144  2.376378596  0.246061389  0.099099518  0.839137422
##  [626]  1.113265390  0.631230879 -1.322045835  3.775536660  1.540737778
##  [631]  1.803197552  1.877262411  2.503019739 -2.428841307  0.320924783
##  [636]  1.454945526  0.971247818  0.250630920  2.505024596 -0.812123724
##  [641]  2.296656640  0.025350537  2.704042924  1.326257390  3.475055219
##  [646] -1.193126422 -0.074277033  2.872582150  4.439193653  0.367387729
##  [651]  2.529196141  3.317462151  0.769774830  3.992741344  1.708427131
##  [656]  1.170443837 -3.011038466  1.161540809 -0.433376408  1.087911018
##  [661] -1.866734645  1.859823457  0.530135797  2.735250496 -0.965762949
##  [666]  3.418136075  3.830421866 -0.181935907  3.029956487  3.085962276
##  [671]  3.159582161  0.616400603  2.259037695  3.330807587  2.218514400
##  [676] -0.515928452  7.032423777  0.558114728 -1.338875531  4.277395323
##  [681]  1.346677614  1.562873336 -2.148303370  3.591154719  0.695761442
##  [686] -0.168719536 -0.089646756  2.165664690  0.639602437  5.269545700
##  [691]  0.488166598  3.831155057 -1.048414580  3.940995603  4.445347593
##  [696]  2.957465235 -1.289572298  3.666670702  3.644722287  2.343000839
##  [701]  7.561324097  0.695459078  1.683251486  3.860705907  2.760762679
##  [706]  3.771959218  0.730208436  1.862823963 -1.877163274  3.265369877
##  [711]  0.696982787  1.022193446  2.762023831  2.734847554  2.570716918
##  [716]  0.184688134  3.022591096  1.620944435  1.404357347  1.370856862
##  [721]  3.853012338  5.091046850  2.576935137  1.397873693  0.718144926
##  [726]  3.665246264  5.213149524  0.795881770  2.072219596  1.861260434
##  [731]  2.585220869 -0.117691297  3.528221629  1.469551498 -2.495651091
##  [736]  4.165891198  4.354868156  1.108771059  0.836592046 -2.510930231
##  [741]  0.867428881  6.928619529  4.541825658  2.482979844 -1.371864354
##  [746]  0.226822822  5.430016879  0.171262249  1.469837710  3.865235020
##  [751]  4.059092787  0.572519695  1.465281518  2.488369542  1.633758547
##  [756]  3.735409772  1.623132844  0.922747849 -0.291090785  4.805971585
##  [761]  2.585120678  6.643253069 -1.541684286  2.960555658  2.986574098
##  [766]  0.905198878  1.463726524  1.803826932  1.531530860  5.026386907
##  [771]  2.826223661  4.265907577  3.291000075  2.363000347  3.429339992
##  [776]  1.316060326  0.050289265  3.981913924  0.164000431 -0.087231967
##  [781] -0.700533881 -0.682638982  3.108513657  2.248896773  4.370822741
##  [786] -0.518750138  3.296922958  3.449046408  1.692051953  1.969298916
##  [791] -0.096389186  2.465125293  2.715045647  2.145791230  0.493953210
##  [796]  0.853929148  2.328788639  1.178996844 -0.898666008  5.106554365
##  [801]  1.277505794 -3.589116477  5.089195957  4.732697722  1.203731871
##  [806]  2.634271574  0.938266240  1.851430241  2.192174921  4.022189593
##  [811]  1.764661418 -0.188200305  1.430729357 -1.115935102 -1.997034497
##  [816]  1.237643343  4.565627251 -1.883770906 -1.774164741  2.852892260
##  [821] -0.800598538  3.565821930  0.364368755  1.196284948  3.269980798
##  [826]  2.194429029 -0.795489739  1.249582666  0.451730453  4.059689464
##  [831]  0.850406362  2.602804074  3.019527958  4.014120111 -1.552748272
##  [836]  2.418776866  1.824635896  1.304806343  3.631409953  2.470579349
##  [841]  4.764632067  5.454973279  1.480871946  2.249226232  1.497324490
##  [846]  2.189462464  0.525026212 -1.028789033  0.319302442  3.865079596
##  [851]  5.024592999  1.859832159  2.345478592  2.092971114  3.918930611
##  [856] -0.715889971  3.666808401  5.477862967 -0.765948516  3.313876573
##  [861]  1.387208324  4.783926312 -0.900362708 -0.526859668  0.794181812
##  [866]  1.456902412  0.900477549 -0.817521754  2.290573214  1.157765906
##  [871] -1.392643007  1.235040256 -3.949213081 -1.071081332  3.197045232
##  [876]  2.315168505  4.508702609  4.705963006  5.509191620  1.408188436
##  [881]  1.745444143  0.985238976  1.710028461  1.033405228  3.436651810
##  [886]  5.993820721  3.572056112  2.678962640  4.235268252  1.969899909
##  [891]  5.233616358  0.677125303  1.171559588  2.654816247  1.757700774
##  [896]  2.889363301  1.852123138  1.306828226  0.852483290  0.326701984
##  [901]  0.990244273 -2.017557923  5.012084550 -0.477647877  1.749127058
##  [906]  3.312612774  2.305235593  2.527981109 -0.306183307  2.933943223
##  [911] -1.468569487  3.290971300  3.933190763  3.027265952  1.412932420
##  [916]  1.914559274  4.437560628  1.786700488 -0.367700579  4.163670424
##  [921]  2.901905879  0.206112798  4.975126972  2.767384045  2.953564445
##  [926]  2.140318700  0.094428960  0.815419490  1.469064229  1.160618440
##  [931] -0.822716469  2.014137891  2.588598802  4.291755764 -2.366097686
##  [936] -0.761780180  3.310372359  4.912255992 -1.571954534  2.737159143
##  [941]  3.568211886  1.484847059  2.898027940  0.521151186  1.006506258
##  [946]  1.622172302  2.296013398  3.280757498  2.222306077  3.419871099
##  [951]  4.254645542  3.593416875  0.190274480  4.171385438  3.407092508
##  [956]  1.172873340  1.263739163  0.991561712  1.144378113  3.219994823
##  [961]  1.523065109  1.831252515 -0.112110283  4.396326199  1.917876793
##  [966] -0.612592515  1.879918355  2.687437541  4.575335173  2.595553581
##  [971]  3.830399377  2.436856278  1.802995893  1.115539593  3.060695082
##  [976]  0.556124206  0.216939984 -1.376052147  2.769601134  1.369991596
##  [981] -0.120704376  4.053323669 -0.600098283  5.076975323  3.276003786
##  [986]  2.598206781  3.847186938  4.746034972  1.966290022 -1.245028377
##  [991] -0.624825696  0.798929262  2.931671896  3.072661813  2.524696484
##  [996]  2.549163385 -0.594017764 -0.315552204 -0.006788059 -1.357367480
## 
## [[3]]
##    [1]  4.770633433  4.861336571  2.219472546  9.391745105  3.560659876
##    [6]  5.121585566  5.300834398  1.672140412  4.324291631  2.039136196
##   [11] -2.242135636 10.150337110  3.856183892  5.620722712  0.692457812
##   [16]  4.213377674  5.789098842 -1.640891807  5.087984858  2.668521788
##   [21]  2.879947428 -0.605400715 -1.580327811  0.893275358  2.708798931
##   [26]  2.255097567  7.864176386 -1.738623121  0.138792671  1.555873988
##   [31]  8.290777330  5.369314096  6.377835416  4.144448349  3.440355169
##   [36] -1.033473986  2.084148289  4.431012315  2.819596225  5.343508894
##   [41]  5.673274307  2.477634500  7.671427152  2.843062967  0.209759392
##   [46]  6.246350988  2.376213835  1.516080915  5.133599397  3.215929047
##   [51]  2.379909000  2.801801536 -1.511154129  1.449660993  2.541938778
##   [56]  0.854449239  5.935834852  6.159860586  3.244995842 -0.705464645
##   [61] -0.354576014  7.955153768  3.992631277 -1.443549144  3.582334855
##   [66] -1.839887065  5.434567432 -0.312735033 -0.114877999 -3.309644954
##   [71] -1.141520245  1.837213179  3.485586682  7.105621030  3.749220262
##   [76] -1.292589955  0.916664293  8.211774167  6.718829489  5.565012341
##   [81]  4.534307253 -0.143547121 -1.650962399  3.242561502  0.729506875
##   [86]  3.152453905  4.325611096  5.226791479  2.161678721  3.954410067
##   [91]  2.914462978  7.711707662  4.359876068  8.115661262  7.986491177
##   [96]  2.247646720 -0.034632818  3.723253789  5.237546410  3.344754647
##  [101] -2.021436610  7.159663933  5.066928103  7.338593689  8.605029491
##  [106]  2.180701223  5.556836066 -1.995911041  5.148948544  3.128371594
##  [111] -0.603520937  0.716426264  7.276658646 -0.269603921  0.043725960
##  [116] 10.471000497  0.039338867  9.693101800  0.262163800  4.159885312
##  [121]  2.473497868  0.168742478  4.887564407 -1.654138744 -4.513306697
##  [126]  3.217561793  0.566439130  0.726605804  4.963636083  4.329444192
##  [131]  1.612369870  0.821620314  2.270888191  3.651237111  5.658444921
##  [136]  5.976761993 -0.678945498  7.292358413  5.250221486  0.303990898
##  [141]  2.193733133  3.200625221 -0.895724968  4.202314071  5.082756282
##  [146]  1.734029408 -2.780703535  4.417113597  4.241466591  3.031672022
##  [151]  3.090119224  4.224320407  3.861250452  7.502036004  4.266983531
##  [156]  5.493157275  6.361227307  2.951224236 -0.369428343  6.690962424
##  [161]  1.415269487  1.478176728  3.316348528  6.108988383 -2.416458918
##  [166]  1.019656978  3.263097727 -1.892449873  5.106231258  4.211977734
##  [171]  1.727996422  1.054852640  3.019820128  0.466549161  0.594162567
##  [176]  3.333803512  1.850893045  4.878702146 -0.055267051 -5.402944770
##  [181]  1.944865796 10.021307986  3.058624185  5.194377793 -3.488497218
##  [186]  0.984408674  7.050375641  5.088954670  1.427322696 -2.112085603
##  [191]  4.761094849  0.061190865  2.096533185  0.339298898  7.196757991
##  [196]  8.971013929  5.034618677  0.410327576  3.578663512  3.012016727
##  [201]  3.764855357  8.079969016  2.850043792  5.379835489  0.694063064
##  [206]  1.664719263 -0.872813179  4.279718623  1.890534543  5.324976331
##  [211]  9.346948995  0.514797773  0.240630750  3.421246103  5.395529429
##  [216] -0.542868076  2.827918278  8.223721933 -1.018326228  7.698344165
##  [221]  6.954646452  8.454231520  7.686081251 -0.948733819 -0.700080937
##  [226] -1.292251702 -1.606194412  0.817841370 -1.124427438  4.072181102
##  [231]  1.250039610  1.232339623  2.085523751  7.643878037 -2.728511326
##  [236]  2.825155785  3.074892746  1.939225742  2.988588126  2.271261638
##  [241]  2.074751258  0.891577898  5.017634577  4.527434911  5.052126004
##  [246] -2.184706703  0.012096756  5.529013409  4.682435320  2.167452350
##  [251]  2.036745501  1.889205849  1.442904878  1.046816009  5.884644777
##  [256]  3.149861091  2.220613145  3.457524008  4.225889688  7.705292699
##  [261]  4.719853240  3.216362735  5.199458132  5.617816211  3.060210383
##  [266]  4.397734320 -0.593682597  4.474984648  6.322324687  2.580314663
##  [271]  3.827713917  4.870040995 -0.078911696  7.947816594  8.479587080
##  [276] -0.294196040  2.960574576 -3.880352823  2.583528677  4.086301800
##  [281]  2.825913684  2.300368907  2.637218281  3.766568238 -1.111898503
##  [286]  4.220520113  8.462941079  1.556435554  6.436608125  1.092375175
##  [291]  7.605831646 -0.179478798  1.711143449 -3.866805962  0.976054279
##  [296]  2.808272764  7.148597401  5.558165230  1.744848589 -1.260989135
##  [301] -0.624774777  3.655582798 -1.242484349  5.328470861  4.346219040
##  [306]  5.927493350  7.056869841 -4.158335936  0.722692506  7.758324658
##  [311] -1.767482184 -2.815156551  5.252565907 -0.858261865  2.762877209
##  [316]  1.814250316  4.293692308 -0.891525132  5.562743402  2.971234699
##  [321] -2.706754911  1.223797942  1.572773007 -2.615848473  8.497864125
##  [326]  3.168939287 -1.848600402  0.642581425  2.857767072  9.215081128
##  [331]  5.755394615 -0.788017282  8.290682727  1.727810762  4.750887655
##  [336] -1.886005046  9.455947519  0.517242687  9.061453887 -1.439684913
##  [341]  0.189278343 -4.467922102  3.127293598  2.276699223  3.091332996
##  [346] -1.662555951  4.515144060  2.105188688  1.899413954  5.122110636
##  [351]  4.944998958  2.138361752  4.434998742  0.867846266  3.008787926
##  [356]  1.664817591 -1.686220418  4.003439933  2.262610045  4.861685408
##  [361]  1.479978844  1.635511945  3.363211971  1.293935247  2.802389785
##  [366]  3.456768156  4.929994141  2.194099843 -3.188423397  3.375792574
##  [371]  1.313553911  2.138069563 -5.818109683  2.393286062  5.343859310
##  [376]  5.586247713  3.174838287  6.237619430  3.940753548  0.127946844
##  [381]  5.702812353  1.275232152  6.986025819  5.534526053  1.276442956
##  [386]  5.992855084  5.369876107  5.230780431  2.056138795  1.039861265
##  [391]  5.195441461  2.891562430  3.290734020  4.103097162  5.330990436
##  [396]  6.414873660  6.056909546  2.490886193  1.023340681  2.139116782
##  [401]  4.402374229  4.492931169  3.240429688  1.113310998  0.950709051
##  [406]  5.569241111 -0.225134783 -1.085404184  6.966249604  1.386541090
##  [411]  2.550899989  1.757205477  1.449671018 -1.129684357  2.449084298
##  [416]  7.533558538  4.425668969  1.907349677  2.021900065  2.113102230
##  [421]  3.679482803  3.856448334 -0.310690772 -0.101908026 -3.092911428
##  [426] -3.086812084 -1.156079835  0.364997473  2.175082952 -0.294374188
##  [431]  2.759084699 -2.268135871  1.547693133  2.434883337  6.697519002
##  [436]  6.551974850  5.363661821  6.578420373  4.070140838 -0.575147803
##  [441]  2.450519857  6.214582858  3.385538883  2.586886549  3.471186773
##  [446]  3.045166829  2.345529724  3.525511931  0.617842570  1.375102331
##  [451]  1.202386706  4.679492929  1.638026882  6.365661774  3.080441387
##  [456]  0.823153976  1.125211356  7.420331021  2.947757344  4.722175980
##  [461] -0.780009489 -1.233668912  2.997708267  0.655390332  4.558776239
##  [466]  0.206336062  3.602698448  4.464915339  1.511633663  2.763500090
##  [471]  8.563461531 -1.881214904 -2.094787323  5.340372991  2.714173089
##  [476]  0.469189922  2.333409689  7.358605617  7.774080554  2.150089123
##  [481]  3.695213112 -0.395019049  4.249590627 -1.937069755  3.940297191
##  [486]  5.093710309  2.448574188 -0.253185533  3.525657004  1.331381353
##  [491]  5.038729655  6.129123927  4.267988870  7.142935195  2.286150838
##  [496] -0.478291343  5.881364360  5.441023117  6.187010162  2.924514099
##  [501]  1.870797930 -4.251539449  6.685047395  3.904792633  0.463490293
##  [506]  1.308154550  6.170454979  7.751599182  1.662494044  4.815671230
##  [511]  6.080560788  5.921215520  2.329353248 -0.645078492  5.677775820
##  [516]  5.663213487  3.691661771  2.435176430  0.327792356  4.516164738
##  [521]  1.341882931 -1.470258412 -0.106968961  4.866519851  2.083376473
##  [526]  2.452875748  6.912120474  5.103577753  8.426729174  0.871973407
##  [531]  4.462231150  4.257209072  2.467274495  3.372848268  2.795012800
##  [536]  1.609118958 -2.489549423 -0.463734368  3.760018463  3.777228460
##  [541]  5.864646014 -1.887079264  3.981271044  4.541163552  2.758376216
##  [546]  2.058024844  5.080923447  3.744441529  4.877858358  2.018008618
##  [551]  3.149707821  2.996155619  0.721406019  7.104185578  6.357975355
##  [556]  5.359737677  4.382848543  0.586672652  6.034848327 -1.265560881
##  [561]  1.612647390  1.963691883 -1.572046748  2.258244312  4.729950161
##  [566]  0.605205668 -3.719215978  7.411604991  2.707705137  1.970495720
##  [571] -1.577915241  4.987180406  4.481303158  1.502005177 -1.939867514
##  [576]  4.746832907  4.749079663  4.484259009  0.755275003  3.710577947
##  [581] -0.701194608  5.438610083  4.389791608  8.170299759  1.152031012
##  [586] -0.477936096  2.203112518  1.503878801  3.799036995  0.396917398
##  [591]  4.203773768  5.601950068  0.869196448  3.690785379  1.685289663
##  [596]  1.797270875  0.329361379 -0.952154877  8.249395563  4.377145974
##  [601]  2.083239892  5.774970807 -0.489724420  3.524323749  6.442280889
##  [606]  7.522791698  5.031468747  4.678454721  3.362561016  5.552125747
##  [611]  3.950655282  1.722488387  3.590148274  5.007158588  1.788989650
##  [616]  6.125309739  8.033707610 -1.744612781  5.200706714 -1.370297305
##  [621]  0.049344758  2.991055018  1.962082962  9.032583955  4.152594186
##  [626]  6.826355766 -1.452029252 -3.478257042  2.429488421  1.560923822
##  [631]  4.587933001  4.124671980  2.524336820  3.790919082  6.029196547
##  [636]  2.906213941  9.059412494  7.853089548  3.509653120  3.367251828
##  [641]  4.853775625  3.667875718  3.200083417  5.363857988  1.255665665
##  [646]  4.633594668  5.989677795  7.008627995 -0.654268856 -0.131535971
##  [651] -1.363680182 -1.065555097  1.032637989  3.644541116  3.519777596
##  [656]  1.681529944  1.652542013  2.955482553 -2.932433972 -1.393077589
##  [661]  1.865277007  5.068908791  1.943180672  5.136798261  5.534685607
##  [666]  3.583095833  2.737993190  4.770522141 -1.595594259  5.324064943
##  [671]  3.875238437  0.938354485  1.286532326  0.918954398 -3.583758014
##  [676] -0.115774947  5.374227537  5.158893495  2.236217290 -1.023189171
##  [681]  4.665878929  3.039530690  0.120402378  5.644432237  3.391013755
##  [686]  4.645450348  1.583896559  5.881696792  1.413359720 -1.864375209
##  [691] -1.526438889  1.353777655  5.594041550  3.366703031 -0.563547725
##  [696]  8.532454754  3.558699826 -3.638061353  2.341642023 10.188619055
##  [701]  9.217806453 -2.011807411  7.042253086  0.697431782 -3.525489171
##  [706]  3.269286356  4.205346572 -4.165578157  1.929394371 -2.726180606
##  [711]  1.263189053  3.265762802  3.652648894 10.009950433  0.286632562
##  [716]  3.372803047  4.709452167  4.675230678  7.017326814  2.915017534
##  [721]  1.145710061 -0.838218039  5.554691314  4.712752647  3.944100395
##  [726]  3.819340350 -0.621896219  6.247905171  7.295679269  4.374069760
##  [731]  7.664282961  8.289670075  7.171077847  3.887148623  5.804460035
##  [736] -0.320628121  4.201951633  0.088459528  2.404545046  5.273147534
##  [741]  0.486994866  4.771759217  2.349600600  3.625058349 -0.630094116
##  [746]  4.734310233  2.589344035  3.522610382  0.338738431  1.796314790
##  [751]  8.091283106  6.830544938  5.879302494  3.095980694  5.063318390
##  [756]  3.517281903  5.607301580  1.107256696  1.296384404  5.934081728
##  [761]  5.525677221  5.463111056  4.974629310  7.158979275  3.619924747
##  [766]  4.088569729  3.155845106  3.547302163  6.387165214  1.397158496
##  [771]  8.275160255 -1.412332783  5.172866997  5.353390537  1.350560568
##  [776]  2.520376797  3.522005379 -2.342696999  3.311315357  7.710232119
##  [781] -2.182751153  7.307233504  3.904516955  4.810800436 -0.601039668
##  [786]  0.892590037  2.233511307  7.562517172  4.736444168  3.946183590
##  [791]  1.711142172  9.448369984  3.323252398  4.158068215  5.239491412
##  [796]  6.069589430 -0.211377328  6.875372882  4.311294306  3.769586564
##  [801]  0.035483566  3.718128347  1.866415042  2.677535938  7.187900762
##  [806]  2.142789894  1.530628912  5.617373865  4.121264013  4.076821452
##  [811]  3.434181056  0.618707220  5.613053648  0.620442877  0.476268491
##  [816]  4.935601173  9.154368856  3.222576528  4.157674786  3.344765375
##  [821] 11.486728127  0.952531019  6.279861603  4.206352652  5.575123400
##  [826]  7.353694519  7.584077700  1.860925872  0.144558668  0.446132790
##  [831]  6.469111866  2.948312115  1.720566592  4.035092399 -2.723442962
##  [836] -1.424101072  0.210589170  8.651567829  0.267037061  3.901078974
##  [841] -0.968636311  0.528224293  4.383011221  1.582959167  9.069946959
##  [846] -3.278457977  4.662376990  3.758360126  0.636582598  4.354670166
##  [851]  2.649161245 -0.448706603  9.729535722 -3.068397349  4.169904551
##  [856]  5.452563743  6.753863646  2.535835336 10.139477034  2.003444279
##  [861]  9.886636348  0.325900046  4.618350802  4.510673905  0.040024332
##  [866]  1.947963080 -1.724051427  5.939525765  4.845038783  5.010641666
##  [871] -1.077280360  2.524677094  0.828921126  4.004239824  7.307274897
##  [876]  2.183300681  7.156114769  0.982497888  0.543589871  5.077933929
##  [881]  0.136142523  0.795580782  2.284430503  1.208559157  5.784963919
##  [886]  4.749633970  6.797782664  2.644929351  3.817419604  1.156932787
##  [891]  3.665825110 -2.052397364  2.233398647  4.638046542  1.566556254
##  [896] -0.903567461  9.990986052 11.392448375  2.066825968  3.560597903
##  [901]  6.101733218  0.181960948  4.013962069  2.156547110  3.995117464
##  [906] -2.316928831 -0.126884560  5.033162619 -1.667236104  4.605298215
##  [911] -1.407528412 -5.302415264 -2.387774156  6.964025325  3.342477408
##  [916] -0.098702943  4.774434864  4.157350471  7.011975719 -0.206333262
##  [921] -2.186507596  1.907630441 -0.452044691  2.004716234  6.055969351
##  [926]  1.489564392  4.228004856 -0.265731304  5.289348077  4.060625598
##  [931] -0.043740296  7.339592421  3.404153848  1.971570463  5.836084308
##  [936]  8.749538768 -0.430291357 -3.063408063  3.597918903  4.454731515
##  [941]  5.461015847  6.060110568  2.659439710  3.236747784 -1.257530476
##  [946]  1.422480302  8.606765030  1.935895456  5.723897800  5.249155007
##  [951]  1.303064752  1.599316166  2.248610317 -1.482758335 -1.358623408
##  [956] -3.276117249  0.009992666 -2.843244293  0.410060812  4.174332285
##  [961]  1.234158965 -0.504713145  0.131608892  4.593462470  2.239769792
##  [966]  6.911107072  3.408456484 12.330892364  0.586223689  1.423143955
##  [971]  3.731818129  3.495500434  2.076295975 -1.311223906  5.817679308
##  [976]  7.784068443  6.215319207  0.441996566  1.857575293  8.264305109
##  [981]  4.997861327  2.148630993  3.669219375  2.344090092  4.421057373
##  [986]  0.695393949  4.379861951  8.408021872  6.246272755 -1.320299406
##  [991]  3.203401361  0.861490274  1.004698188  3.835438187  4.602761495
##  [996]  8.873381417  3.308054603  8.491091736  6.830780867 -0.445396822
## 
## [[4]]
##    [1]  2.73682808  6.43471496  1.28628689  4.07880749 -1.60383703
##    [6] -1.86571544 12.77478079 10.24369679  5.19355107  7.49073645
##   [11]  6.59876320  6.87638404  1.90426216  5.36518146  1.12162697
##   [16]  3.63525762  9.03676718  4.82076306 12.09256413  4.91609458
##   [21]  3.94526975 -5.26870669  6.36131523  9.46488411  3.88077149
##   [26]  4.37868717  2.87856927 12.13947359  7.91488305 11.58307074
##   [31]  1.63873119  0.23201996  7.18072359  2.36596845  0.43419719
##   [36]  8.21178049  4.88990568 -1.28423190  3.82237941 -2.14307805
##   [41]  7.52224026  3.89295666  2.54608684  3.90146541  1.01970182
##   [46]  0.21004148  2.80153123  0.71140114  6.24370588  5.21396395
##   [51]  6.70604895  2.88239510  3.94361738  8.66325618 -4.19001595
##   [56] -0.53819240 -1.11125715  4.20688165 -2.65771313  4.24374456
##   [61] -2.61710845  5.22631864  8.30519888 -5.68331892  1.77901230
##   [66]  1.75054585 -1.83970237  1.34675910  1.89530042  7.95528644
##   [71] -2.47115665  0.59403361 10.91688646  4.71618004  8.04706531
##   [76] -2.19156929  1.12721809  4.67880179  0.78698471  6.28364456
##   [81]  2.63293559  0.65822287  0.87768476  4.12925383  4.42065706
##   [86]  4.53399253  4.43295734  0.67534707  7.52934349  9.56437317
##   [91] -0.38587058  7.89656709  9.07317354  9.23969234  9.25732863
##   [96]  1.53920944  0.13145249 -1.91362428  9.34150895  5.14812742
##  [101] 13.43275585  6.15066007  1.37392408  5.51206477  1.54876922
##  [106]  9.00562542  8.40255570  6.27732461 -3.80765192 14.43215680
##  [111]  4.08958699  4.16327058  9.37706970 -0.39219344  6.82007319
##  [116]  1.83964187 -3.35316863  6.17367174 11.26183249  5.86168428
##  [121]  0.85848619  5.66362556  5.97709909 11.19157117 -2.32222683
##  [126] -5.94454234  0.58661545 -2.79610756  7.28583499  6.91673624
##  [131]  9.91181766  5.92051775  1.72797287  3.23017492  7.43930278
##  [136]  4.20454123  9.64234283  1.48563329 -0.25898716 -0.64607874
##  [141]  5.76774981  8.68013988  9.10635351  2.13588656 10.68277763
##  [146]  1.11641613  7.49395812  8.46573681  0.78491647  3.79984505
##  [151] -1.90167480  4.14934869  3.48473366  5.33742552  5.42704419
##  [156]  4.70996143 -2.76430711  0.78376691 -6.86349119 -0.69192375
##  [161]  6.09358059  5.12445137  0.18244692  9.94252159  2.72627810
##  [166]  4.16258085 -2.35417501  8.39818126  5.86982982  8.64323216
##  [171]  9.51749731  4.67405253  9.06525459 -5.23911142  4.70515293
##  [176]  2.80144610 -0.84840951 -0.48354246  8.83556428 11.89620820
##  [181]  3.48856558  9.18710915  6.70426610  2.25804360  2.70558376
##  [186]  8.76899693  7.75751976  9.88269235  0.70550674  7.44891047
##  [191]  6.28157594  3.72706337  6.82909798  4.49427018 -2.00642330
##  [196] 15.02499979  0.51808953  3.40825687 11.09204651  5.82432307
##  [201]  5.98795099  7.48675266  3.75081522  7.45829741  1.13783993
##  [206] 16.33627005  3.07505735  4.78652789 -0.20291518  8.79782983
##  [211]  8.53251214  6.58910816  1.49922080  8.74403224  6.42228868
##  [216]  3.67361570  4.90035049 -1.57317278  4.57125321 -3.98611434
##  [221]  0.69295861  5.69711543 -1.90025469  7.01235984  6.96291778
##  [226] 14.87708852  1.85053756 14.02972212  5.97832151  3.71309847
##  [231]  3.11678680  7.23839814  5.59203317  4.44367893  6.12704920
##  [236]  7.90842337  3.44297137  2.19366015  7.93937080  1.79886447
##  [241]  8.57513706  7.59935219 -0.93692810  0.57020916 10.39677541
##  [246]  4.07837313  2.07656789 -7.05983632 -0.85122676  0.65814596
##  [251]  6.81393414  4.83827451  4.25464179 10.28440763  2.58970699
##  [256] -2.56129368  5.62247763  3.29919898  1.16038998  6.04043428
##  [261]  5.66996155  4.26982405  7.39799115  4.38894463  6.83922914
##  [266]  0.03110225  1.21467097  5.86351079  1.54496805  0.17006072
##  [271]  4.05381136  0.79999741  6.37087967  6.40068107  7.48521624
##  [276]  6.49105738  2.51430547  5.61696857  4.26931588 -3.13096089
##  [281] -0.83665087  0.65526972  5.29514568 -1.39143267  3.89158404
##  [286] -1.06487195  0.67653643 10.04474010  8.97227957  8.74917316
##  [291]  4.59288408  0.28833419  7.21622112  3.49198432  7.84519655
##  [296]  4.19929824 -1.71020482 10.02808865  5.33825323 -3.97953926
##  [301]  3.51798751 -0.49098583 -1.17324410  3.36316638  7.60616913
##  [306]  2.39909110  7.55113803  1.60662476  8.06705924 12.29217430
##  [311]  5.28096590  0.95704890  4.51926889  2.33051079 -0.63667524
##  [316] 11.56937157  5.98440648  0.24935598  5.51796222 10.64573745
##  [321]  7.13708545 10.70487580  4.35040710  8.90944609  3.94358986
##  [326]  4.38384429  7.12334926 10.00382913  4.57416657  7.06839417
##  [331]  1.01444991  5.50102111  3.34576564  0.98912591  1.11451279
##  [336]  9.15955009 11.85054897  8.81561793  1.64909107  1.41488297
##  [341]  9.96211421 -3.19378607  1.95576514  6.42103103  3.75929401
##  [346] 10.78373371  4.77151669  3.74579063  8.53716605  4.43205763
##  [351]  7.20349690  6.63713051  4.18466430 10.59259251  0.76222903
##  [356] 11.01665092  5.28440687  2.39110067  3.79579572  1.90148839
##  [361]  5.87278489 -4.13468953  3.77648890  5.15696086 -4.17697108
##  [366]  8.59001537  5.95958679  6.72485646  1.96857559  7.59055740
##  [371]  0.87148210  6.78005659  8.92934855 -1.49765650 -0.11066633
##  [376] -0.99017087  6.04895421  0.54569595  5.70787752  4.71065633
##  [381]  5.23116589  8.39433524  1.31476256  4.15097373  0.77547762
##  [386] 13.30965344  2.09756665  0.70906561  2.65373860  4.94195620
##  [391]  3.88938599  5.72490989  4.00129585  2.16444675  6.83045606
##  [396]  7.83103322  5.93073867  3.44484737  3.80981496 -2.34544951
##  [401]  9.58887004  4.00008643  1.85792459 -0.02515946  2.40138272
##  [406] 12.90675195  9.80265586  2.47082403 -0.76844011 13.60769624
##  [411]  9.36826818 10.72639443  3.46096578 10.30052733  4.26981075
##  [416]  2.28782402  3.23104176 -7.65476736  9.54285932  3.44924526
##  [421]  2.04019776 -0.24469840  7.67851777  1.88439744  9.81495069
##  [426]  6.54187490  5.26208369  9.46083202  8.74018678 -5.67920225
##  [431]  6.49542731 -0.52891878 -0.13972480 12.45892126  2.89652000
##  [436]  2.50129492  3.85852774  3.74570829  6.56180422  4.81480421
##  [441]  7.50857401  7.29314437 -1.83358588  1.42251865  9.59238142
##  [446]  4.30380923 -0.05325168 -1.07284593  2.92911613  1.44220195
##  [451] 12.67837507  3.89355956  4.17775314  3.04128277  3.10763774
##  [456]  2.06747977 13.71911715  6.07166129  6.28465413  5.61908403
##  [461]  4.03039419 -4.33270157  1.39868894 12.34747360  4.93207967
##  [466] -0.29845829  6.59439034  0.99067747  2.75992913  5.35283982
##  [471]  4.45243489  3.72409140  9.36744816  1.92701767  5.71881881
##  [476] 10.31334068  5.87235120  8.21101067 -0.80418037  6.90719216
##  [481]  6.09270261 -2.92460467  2.16536368  5.04996073  7.33236503
##  [486]  2.92034483  5.13729178  3.96372063  5.23129043  0.61577220
##  [491] -5.22388292 -1.17296988 -1.30878423  2.52631686  7.86708203
##  [496]  0.25150295  1.54527816  7.75777191  9.31357334 12.11521701
##  [501]  0.18268820  9.56309191  2.37228410  5.57399061  1.52431121
##  [506]  4.58852696  2.99529088  2.98972755  1.81834511  0.88295009
##  [511]  9.33983002  6.71072541 -0.26706337  0.70362315 -0.33109537
##  [516]  5.79380321  3.74149247  6.88678193  9.41053545  3.90436618
##  [521] 10.55560117 -4.32435274  8.14976625  3.41565106  5.22826708
##  [526]  8.46542374 14.12916005  7.29827380  6.34079240  3.01867655
##  [531]  0.40234407  3.34740064  9.52790689  5.76767239  2.18525055
##  [536]  1.78769986  4.91635029 -3.38142220  8.14809139  3.87973719
##  [541]  5.63362223 -2.53979538  9.45059953  4.53861041  4.52450595
##  [546] -0.84365788  7.25707158 -1.81605631  4.80966654 -0.37719654
##  [551]  4.09277678  8.27792615  9.68452435  3.28809091  2.47413143
##  [556]  8.68192562  9.44958550  3.40511735  1.40134788  9.55384688
##  [561]  2.73423122  7.02149299  2.19203578  6.53665918 -0.11493691
##  [566]  7.56853901  5.02142669  1.41795194 -0.04548809  4.99580517
##  [571]  5.30186946  2.94151522  9.23153041  3.07368586  5.44913125
##  [576]  1.88793113 10.47150411 -0.87269094  2.54076211  1.57882247
##  [581]  2.49462882  3.22293909 -4.12117638  2.08280958  7.41549302
##  [586]  3.87718539 10.98038367 -2.46333821  8.43258609  2.72918065
##  [591]  6.00532905  5.47720130 -5.76321457  4.92276620  6.64076628
##  [596]  4.30452703  4.81753640 15.59453515  1.82118310  9.40653383
##  [601]  4.89236864  2.63164289  3.02783680  3.29461572  3.16818426
##  [606]  9.43678847  2.74561912  3.79041443  5.65419928  1.25285836
##  [611]  7.90488561  8.82697544  5.22640845  9.24572958  6.79151479
##  [616]  5.42799314  7.94924217  8.18014999  6.13114097  9.60390548
##  [621]  3.49670430  0.35200052  0.87093666 -2.34943006  3.78368487
##  [626]  3.68918957 -2.99192365  3.48614737  6.36611615  3.06258258
##  [631]  4.51080355  5.92657630  6.91609085  3.93691828  2.21297679
##  [636] -0.86174873 -3.91027619  2.11102537 -2.16213383  8.06740350
##  [641]  1.41425644  4.00906014 -0.54496133 12.06117750  5.35171233
##  [646]  3.37059534  0.65302667 10.23630654  4.08253194  0.68711444
##  [651]  5.88119180  6.45263087  8.20557468  6.00011323 -0.51234339
##  [656]  4.64543828 -2.08973778  3.65725732  0.32806066  3.86382281
##  [661]  1.27525657  2.73446366 -1.36418201  1.11692179  3.38723650
##  [666]  2.69727440 -2.01759243  5.57416352  1.27265425  2.03104792
##  [671]  2.35589951  6.08363281  2.17452880  2.43778845  6.21719557
##  [676]  1.23325149  6.52976617  1.59904472  7.07458604  0.83715677
##  [681]  4.54485678  1.24864433  3.49086701  8.16292360  6.53567029
##  [686] -4.00926500  1.22001448  4.56446968  6.49793451  4.78248431
##  [691]  0.68842851  4.86187224  7.58575336  6.44763955  6.09278894
##  [696]  3.37676296 14.58651779 10.31462490 -0.51442565  5.99984402
##  [701] -2.67241578  5.62216969  7.07441414  9.04982264 11.57932078
##  [706]  3.09955021  6.40182476  6.26852894  6.06602020  4.69270310
##  [711]  6.13436700  5.45013399  4.58112614  7.60882036  4.19755193
##  [716] 10.59657153  6.37631089 -0.56037968  5.57854237  4.19708146
##  [721]  5.78917163  8.91859184 -1.98935841  3.65075501  3.84355866
##  [726] -3.24741735  6.75794362  6.97426789  8.68467494  1.35229936
##  [731] -0.26211183  2.61197204  4.71726989  4.47752962 -1.10129528
##  [736] -1.25997432 -7.56782259  7.36997221  5.75319493 -4.22923961
##  [741] -2.57267169  0.95309046  7.57350376  4.09971589  9.09036895
##  [746]  6.30403911  9.75169362 -0.34417339 -4.44945202  4.55263751
##  [751]  7.11735720  5.08329676 -2.77737692  3.89037017 -0.04336854
##  [756] 10.18114274 -1.76346034 -3.65963250  0.33489621 11.26775311
##  [761]  3.57473173  1.90409332  0.83819623 -0.85069260 -3.28358858
##  [766]  0.97280159  4.25887000  4.67748384  0.48749170  3.86259277
##  [771]  8.76677025  2.96449831 -0.91310985 12.69584132  6.69823627
##  [776] 10.70085527  4.00380579  2.71387013  0.09741676 -0.38609436
##  [781]  4.67533455  3.57373017  6.27212270  3.78583783  5.98152651
##  [786]  4.51717333  6.23879241 -2.13212612  8.44854138 11.35871290
##  [791] -2.40100142  7.76606323  4.87881774  1.69293398  7.30102646
##  [796]  0.82641092  7.33093156  5.94140025  3.16192034  4.68307984
##  [801]  1.30376958 -0.17696865  1.21785467  2.97089999  5.97058606
##  [806]  4.10178654  1.47424037  6.18722427  8.28083829  4.92583772
##  [811]  9.13512843 10.67133185 12.24951378  6.10345015  1.48902154
##  [816]  0.65097241  0.73958150  8.89252894  6.43467531 11.26374403
##  [821]  3.85789227  3.47799538  8.64904685  6.66682455  7.88733179
##  [826]  8.71940240  7.90968769  7.91374196  9.12383157  8.08421641
##  [831]  6.47392059  3.64321626 11.44368230  8.44592483 -0.37776058
##  [836]  0.71719843 -0.71859166  5.57558911  8.06663898 -1.76215105
##  [841] -1.74015138  6.17341891  5.59615141  6.24983894  2.14667656
##  [846]  8.35481561 -0.95347946 -0.95247392  9.63996750 -0.29839890
##  [851]  7.18423127  1.58782085  3.02072372  0.21807840 -1.57784124
##  [856] 15.35206098  1.93447110 -4.11729807 10.59249361 10.63475012
##  [861]  3.26326613 -2.45388654  7.86782233  0.72146781  1.85284667
##  [866]  0.19962972 -2.18518271  1.31237899  5.63265468  8.89727787
##  [871]  8.31981977  5.71156143  7.91696626 -0.17096840 -5.38134179
##  [876]  1.65955771  8.99136032  1.29578968  2.38957657  3.63550352
##  [881]  2.63493504  5.36925429  7.26361399  6.72330977  6.31165309
##  [886]  5.95031056  7.10825632 14.78157227  4.63953453  2.13562823
##  [891] -2.33681115  3.12947759  1.88516558 14.23716030  9.26984091
##  [896]  0.83046053  8.14406965  5.10564168  6.86479793  4.61013341
##  [901]  0.15922338 -0.81365268  2.13282391  2.54925555 -3.55562467
##  [906]  1.71837690  2.20493180  3.56216524  0.62824274  2.40163819
##  [911]  4.31252438  3.88517098  4.37812732 -0.22174507  6.05282884
##  [916] -2.72860204 10.66545697  3.32275220  5.72849716  8.89133615
##  [921]  5.46268660  7.11209211  6.27677847  4.78695948  2.15461835
##  [926]  7.08075096  2.11510494  5.06270325 -1.86939803  0.19581409
##  [931] 11.49732463 11.15812795 12.07385665 12.68234583  7.27857730
##  [936]  5.08217708 11.25810159  2.75265335  2.09149805  6.37976777
##  [941] -5.52593502  6.81294809  8.45254605  1.39728722  5.90271087
##  [946]  8.20400621  6.12542798  7.12848066  1.97907217 -2.99548969
##  [951]  2.71775703 15.27918025 -3.26660084  2.61435423  3.74953191
##  [956] -2.96214672  7.95009438 10.30751915  3.22125649  3.53897496
##  [961] -1.89036988  6.08662844 14.11931926  1.41969285  6.29046988
##  [966]  3.03758037  6.54338676  4.51210389  1.95310435  3.59330889
##  [971]  0.83925140 -0.05183834  4.78204124  4.29517945  7.59155015
##  [976]  6.12373287  9.32454573  4.53182760 10.48858284  3.10954274
##  [981]  8.08077130  4.29430985  5.46108216  3.27200776 -0.98936775
##  [986]  5.61245949  8.45073639 11.53328463  7.33360777  2.17785126
##  [991]  4.02673249  2.82589181  6.37308680  2.17703416  2.12089529
##  [996]  4.34692658  8.95440032 -3.68895622 -3.88805575  2.62295331
## 
## [[5]]
##    [1]   7.770096232   0.285473508   5.739724545   8.116735340
##    [5]  -0.242776376   4.352965021   3.625902504   5.109656308
##    [9]   4.015628379  10.329866650  -1.703265181   0.530817038
##   [13]  -3.003621177   5.731795390   1.925707025   1.390340083
##   [17]   1.613405012   7.483005773  -1.077453653   9.025454165
##   [21]   2.738386953   4.666181285  11.975023378   6.017799341
##   [25]   2.734322491   7.127061079   7.833830205  11.424477381
##   [29]  -0.511097151   2.970654949   0.166650138  12.144358288
##   [33]   5.539311850  -2.496708098   0.082620318   9.858176322
##   [37]   6.471608323  14.450483058  -1.854697966  10.967931098
##   [41]   4.184463848   1.937633784  14.175854203   0.002046747
##   [45]  -2.265309858   9.207880191   9.676466555   9.498213048
##   [49]   5.825000916   8.781824861  -0.914925137   7.129238163
##   [53]  -4.842016791   0.604830480  -4.996742599   9.922097472
##   [57]   5.282924662   0.170563495   0.866564229  -3.357947407
##   [61]  -0.804570991  10.871563329   8.267612264   6.814877516
##   [65]  -0.797281539   9.809335164   7.775954028  -1.705791741
##   [69]   3.498269871  15.010961328  -7.400768179   2.646484219
##   [73]   6.904599852   6.306420466   1.906152481  -1.809896716
##   [77]  -4.328356557   4.210033391  13.322947516   3.353073482
##   [81]   2.215557012   3.002124316   6.821450030   6.484749769
##   [85]   9.413961637   8.874980668   3.725475473  11.005429378
##   [89]   6.111715918   7.779052686   0.879376498  -1.130860959
##   [93]  -1.708125561   7.472814549   1.734843657  10.494505465
##   [97]   7.716348725   3.026403989  -5.521418230  -9.728688948
##  [101]   4.345526686   4.076592612   6.359270643   8.624244411
##  [105]   2.903358247  -8.121074157  13.368677808   0.846904451
##  [109]  14.006916590   6.358145768   6.576430124   5.118987728
##  [113]  -0.278847315   0.540826952   7.661231946 -10.482619760
##  [117]  -3.470719177  -6.635985360   4.121558887  -3.162041990
##  [121]   6.332162147   2.512998309  10.333251916   4.128002340
##  [125]  -2.909225816 -10.588335315   6.665038519   2.947108726
##  [129]   0.679997253  13.024428263  -1.999235369   0.563650241
##  [133]  10.632786733   4.023250535   1.852659176  11.908011072
##  [137]  -1.190381271   4.869581341   7.734799033  12.993465309
##  [141]   7.718583980   3.945543237  -4.168644063   4.660019370
##  [145]   6.070076801  12.333573092  10.648513871   1.462477037
##  [149]   3.237729184  13.636589310   7.905492216   9.675014246
##  [153]   4.392108754   6.723211534  -1.898788931   2.131774969
##  [157]  -5.663205395   6.978705947   0.527934705  15.930213659
##  [161]   7.913542607  13.613126898   9.932878694   6.049952905
##  [165]   1.899399653  14.811788003  17.692886602   4.975696425
##  [169]   6.851297127   5.716430278   4.774125885   0.687727247
##  [173]  -1.117305244   2.786244692   0.237773013   1.028862128
##  [177]   3.733178835   3.612508420   9.272855658   6.903327499
##  [181]   4.873962766   1.382821226   7.734739643   0.126484303
##  [185]  17.434625867   9.513079627   7.207253076   2.529632995
##  [189]   1.700454998  10.198380992   4.442886081   3.342695175
##  [193]   0.673294231   2.474054776   7.244180326  -3.217645348
##  [197]   2.780124018   4.779534268  -0.292777623   6.580206773
##  [201]   1.923680846  15.094643969   0.195769387   3.729371476
##  [205]  -4.530108032   8.221908808   3.360452436   4.906858931
##  [209]  10.035764131   0.509021610   6.819959952   4.128446013
##  [213]   5.903537976   2.926114946   0.015026260   3.857271559
##  [217]   5.012696634   8.758013599   3.616544600   1.788432183
##  [221]  -0.672121908   0.503405201  16.680343410   5.710127221
##  [225]  10.305679464   7.461001214  14.832639037   7.457985913
##  [229]  -2.415871215  19.724510552   9.802584102   2.853821989
##  [233]  13.988266381  15.809128987   1.953143520  -2.866525587
##  [237]   5.541483212   1.735248903  -2.670700035   3.291078545
##  [241]   5.272830309   2.628087467   4.291234196   5.191279245
##  [245]  10.418138209   7.894550506   4.354573601   0.857782330
##  [249]  12.068957446  -1.880341604   7.992296627  -2.095578150
##  [253]  10.353626098   1.237128571  16.264920748  -3.176066114
##  [257]   3.358322077   3.818580898   5.724766580  -1.366431588
##  [261]   9.293801587  11.849592798  -3.297444420   6.034455118
##  [265]   5.234121195   5.347704543  10.801512057  13.756234481
##  [269]   7.649431213  -2.431873668  11.688265454  10.283669937
##  [273]  -2.397606095   3.838789935   3.733065031  -3.534730809
##  [277]  -1.987922188   1.289215984   2.533105821   3.595444199
##  [281]   9.314363241   8.107368761  -0.220942294   8.243495899
##  [285]  -1.129237872   7.264370747  12.209731001   4.494844775
##  [289]   3.390426850   3.998537359   7.785540780   4.419870388
##  [293]   5.725978551  12.793210822   9.968278341   8.406592717
##  [297]   2.686869192   5.347136716  14.772263858   2.451452569
##  [301]   6.948688569   3.520427381   4.556510398  11.331311785
##  [305]   6.203763404  10.972856722   3.478965254   8.106157911
##  [309]   4.575059967  10.116639034  10.175066952   2.250279321
##  [313]  -3.466037840  18.234065103   9.242546685   7.101236314
##  [317]  -3.847016237  -0.780516868  -4.848921042  10.499982247
##  [321]   7.491597309  -2.996367965   9.634888593  10.261192787
##  [325]   6.555454266   8.591566038   4.202516670   1.875617116
##  [329]  -1.159829599  -0.362658319   4.792150267   4.810480908
##  [333]   4.328558230   8.009794607   7.688840988  -3.111386312
##  [337]   8.516915995   1.249510678  -3.479682919   3.431292400
##  [341]   5.426515147   4.158844852   8.300102577   3.695247587
##  [345]  -2.828898366  13.135319850  -0.691166136  11.448652137
##  [349]   9.864225296   2.589899833   6.535840371   2.558005515
##  [353]   6.232027673   6.301807103  12.725015491   6.778224944
##  [357]   8.659066876   3.293992005   7.359999325   7.662101356
##  [361]   1.948321983   6.311674530   5.344500190  12.779768599
##  [365]   2.043324082   8.869790298   8.371205341  10.977332356
##  [369]  11.416304649   2.288261670   3.479205926   3.487904158
##  [373]  11.652872305   8.423929011   6.577413134  -2.512279200
##  [377]   3.166279784   2.430431115   2.424073144  10.808259536
##  [381]  -1.137226906   3.391368632   0.316421261   0.805028410
##  [385]   2.492772826   4.431920260  -2.617092069   5.297570073
##  [389]  12.047137350   5.320914235   6.813945862   0.939781851
##  [393]   1.617344399   7.525060090  10.998900027  10.324212802
##  [397]  -2.301180927  -2.197345970   5.245157605   2.778084883
##  [401]   3.293232278   5.911348730   4.003460179   6.540434436
##  [405]   4.910990755   8.717744460   6.521117741   2.041978101
##  [409]  12.801874189   2.130638860   3.849204115   1.960296931
##  [413]   5.058900975   8.205881894   2.552125631  -2.296031788
##  [417]   3.908680459   8.876789491  14.448453519  -4.213337150
##  [421]   2.555404691  19.116892850   8.859905662  -1.250635926
##  [425]   9.997475823   3.576085485   1.971386285   4.745312410
##  [429]   7.956046239   3.576507556   5.692000868  13.382783029
##  [433]   8.509258566  -1.130020359   5.199688840   1.865095180
##  [437]   5.548640519   3.475167730  -1.232949523   4.777987978
##  [441]   3.407486513   8.204403150   7.104986438   9.855661083
##  [445]  -2.036677440   9.874450596   5.115599386   9.358096560
##  [449]   0.432020034   3.219249437   9.879760468   2.054413064
##  [453]   3.192414955   3.616774696   6.002935409  14.855050803
##  [457]   6.110623323  -1.501971647   0.736777864   2.728319834
##  [461]   4.114860692   7.400623420   2.052315804  -3.469390873
##  [465]  -0.166070652  12.126484009   6.299370354  16.204019569
##  [469]  12.038429113   3.590703050   2.681020296   5.237198734
##  [473]   4.111724602   5.224731418  -0.748738211   8.133497332
##  [477]   9.932413979   5.901910668   8.641386401   8.737013497
##  [481]  11.719594507   6.797037423   5.459075606  15.208290521
##  [485]  -1.027148457   7.118903748  10.207577583  -1.977871096
##  [489]   2.448940096   4.132828781   6.929385690   5.966449063
##  [493]   1.946812183   3.637183583   1.964060680   3.055239647
##  [497]   4.514610819  13.102924297   6.989158605  11.787934259
##  [501]  -0.284745215   9.605059251  10.007463357   4.283866681
##  [505]   5.272951379  -1.259904597   4.597145250   9.852819103
##  [509]  12.213512835   7.780376569   3.809526818  12.189385531
##  [513]   3.079500721  -5.429574323  -0.041042016   2.760415560
##  [517]   5.675090470  -1.603828367   6.510002029   6.007846768
##  [521]  18.990103958   4.847340506   1.610584369   5.725946769
##  [525]   7.461699478   8.534326384   3.439835210   5.895330978
##  [529]   2.326970663   6.459847931   6.645485631  11.106098933
##  [533]  -0.947734589   3.684356798   5.796691321  -3.373772124
##  [537]  12.238864539   7.016671571  13.978836027   6.466067120
##  [541]   1.558814092   1.788917756   7.053869862  -3.271204762
##  [545]   1.237713823  -5.974132346  10.073451850   9.996848502
##  [549]   7.800891076   4.621447689  -1.431554445  12.260527924
##  [553]   8.884994187  13.267979381   9.568557951   5.999746368
##  [557]  -6.807859762  -2.702510824   9.428651755   6.297686867
##  [561]   5.731200375   0.303983962   5.075933466  11.042370268
##  [565]   3.017371392  12.543083075   6.917580341  -6.210541605
##  [569]  15.967562529   6.314811313   4.881219305   4.684353715
##  [573]   8.940680991  -1.969915764   9.686163842   0.479048086
##  [577]   9.224200887  11.614984749   4.924807145   4.532422244
##  [581]   1.973402494  -1.310362157   3.595137345   7.808877805
##  [585]   3.304635472   2.264313579  -0.211414847  -0.256145941
##  [589]   9.136930647  14.004668667  -2.493984869   0.949398713
##  [593]   8.442057595   6.843315237   7.381984783  11.334071500
##  [597]  -1.124661275   7.097112844  -4.486149715  -3.510095559
##  [601]   4.576888029   5.372536036  13.071071723   1.407335424
##  [605]   7.669890758  -1.441107042   4.698735272   5.210323194
##  [609]   2.164289241  -0.558331022  10.480120263   2.694934766
##  [613]  -0.087623819   8.131050920   3.397207544  13.331354408
##  [617]  10.224453557   2.477620604  -6.445304963   2.602656845
##  [621]   9.666076946   2.316934696   8.837065597   5.662362307
##  [625]  -3.906911875  13.840818071   8.354019791   0.639887428
##  [629]  10.095136652   9.300714017   6.526957967   2.240544075
##  [633]   4.957313957   2.722039575   9.137759931   6.698972817
##  [637]   5.307412471   0.865562359   1.963018787   1.841367688
##  [641]   5.118995929   5.163763345   3.853519187   8.885862567
##  [645]   8.644703484  12.300494624   3.178803993   9.972827253
##  [649]   3.695389384   0.064613927   9.880873066   2.702524930
##  [653]  10.530594738   3.709150592   1.360948749  -1.948984254
##  [657]  13.493158013   4.538824618  10.213222212   0.456638241
##  [661]   5.063400910   1.614357821   3.946982959   6.953914207
##  [665]  11.975577020   6.857771753   3.031222225  -5.689952214
##  [669]  10.815540529  -0.345677393   3.564740292   1.975556534
##  [673]   6.560126365   7.080727295   3.067467286  12.644231301
##  [677]  12.965008013   5.031357864   0.814657644   9.324259243
##  [681]   1.998104191   0.237106617   8.335496004   6.711165178
##  [685]   3.379577986   8.057381198   4.891140016  -1.976965691
##  [689]   6.867356291   6.253459308   4.134334566  11.282433403
##  [693]   2.519355800   0.185418956   9.110190812  -0.136011885
##  [697]   5.933097608   4.296580179   7.132165661   2.039719005
##  [701]   2.238886200  -6.599773689   5.977501892  13.388591145
##  [705]   7.300441855   3.303616473   6.042682390   8.738509268
##  [709]   8.513659592  -3.447732582   3.361796078   9.680386421
##  [713]   7.613754656   1.750089543   5.803964837   6.393826241
##  [717]   3.824250836   4.632686154  -3.068732035  14.510249707
##  [721]  13.903877922   5.047838275   4.335105416  15.259486786
##  [725]   6.154109237   5.333921609   4.708607705  -0.134098050
##  [729]  -7.293960683  -0.474218746   2.172582907  12.549873686
##  [733]   5.874316263   7.986828533   1.736779262  12.513783059
##  [737]   0.038888483   9.569226272  -2.713804047   4.998153279
##  [741]   6.563195811   1.606375887   7.173870734  13.991650913
##  [745]   1.270944266   4.182709544   2.075390099   7.204295325
##  [749]   4.957436807  -2.851612168   8.767068295   7.453223506
##  [753]  -1.077935863  13.785523868   6.718030964   8.453926919
##  [757]   5.172683531  -3.465289053   6.880834832   3.975613135
##  [761]   2.037882318   7.536403653   5.773716055   6.485519532
##  [765]  -4.616233959   3.293508512  15.564680847  13.454628284
##  [769]  14.142172971  -2.041991660  -1.675664235  -0.506379851
##  [773]  -2.184871597   0.736998014   6.961745345   7.578766702
##  [777]   3.340111266  -2.331569031   0.899044938   9.249531855
##  [781]  -2.212021071   5.401227425  -2.267015878   2.302010817
##  [785]   6.079593207   7.729714996   5.661879447   1.792361443
##  [789]   3.058067166   6.631323985   7.285693598   5.131252732
##  [793]   1.154968296  -1.631771907   6.105576419   3.933438537
##  [797]   7.912877164  -0.906889645   6.062753372  -7.310900528
##  [801]  -4.351353340  10.195993344  -1.569286927  14.407530906
##  [805]   6.022114707   4.108414959  -4.183095342   7.419595516
##  [809]   2.034759006   4.102892479   4.897867540  11.221754391
##  [813]   7.677778518   3.853959061  13.509997609   4.517030259
##  [817]   4.235566287   1.838306323   4.812049195   8.545471473
##  [821]   2.541901601   6.851244659   1.860833209  -0.516031995
##  [825]  -3.478122987   3.526094883   9.460220256   5.560141621
##  [829]  -7.283726805  10.424176217   0.949701488  11.504298686
##  [833]   0.525429151  -1.371514011   2.887742154   5.170670788
##  [837]   5.009298274   4.024197380   1.979129979   0.535416640
##  [841]   7.566195421   6.780504828   7.472455506   6.492304647
##  [845]   4.958779972   8.374916146   4.225744739  -2.617184780
##  [849]  11.403182205  -7.394231376   4.990746622   4.289314185
##  [853]   4.805394437  -1.410317052   4.037203953   1.981062236
##  [857]   2.974765847   8.650356383  12.255458375   3.634172636
##  [861]  11.315376701  11.574527745   4.343679622   1.699091619
##  [865]   5.759277160   2.462829288   9.690475378   5.918060497
##  [869]   1.834555503   4.383101403   8.719179490   8.898595082
##  [873]   5.214079316   6.414502886  11.677422818   4.900466486
##  [877]   9.529804200  12.139826725   2.381000226   4.598579994
##  [881]  10.413666712   2.203060238  -0.593212415  10.329949086
##  [885]  12.496358097   8.521232297  10.316433169   7.506182152
##  [889]  12.478007937   6.006402966   3.642729925   4.592271125
##  [893]   4.964410240   9.772572323   4.296052846   8.143643606
##  [897]  11.393089044   4.518062113  -0.363368533   0.009993704
##  [901]   1.173786479  -3.933795690   6.134693445   5.863289857
##  [905]   7.247018283  -1.848586903  10.890736145   3.968872011
##  [909]   5.139412571  12.602263614  11.343242812  12.735954653
##  [913]  -1.203268605   1.850717766  14.120400900   0.147169411
##  [917]  10.209364736   7.328275099   8.097179967   2.743137956
##  [921]   3.576327801  10.826922130   1.356150834  -0.736258571
##  [925]   0.872982778   2.346119069   3.265494768   2.702492595
##  [929]  -0.517012882   9.425936878   4.286796379   1.424342099
##  [933]   4.183800785   5.992676365   1.263808010   2.593606165
##  [937]   9.804965646   4.981999043  15.120128609  12.800506174
##  [941]   4.124534184  -1.896493037   1.760468808   6.975414258
##  [945]  11.611819589   1.614077978  14.548983520  -0.299433584
##  [949]   2.434160541  13.195362792   3.574858155  -1.173880428
##  [953]   1.400061470  -1.561020514  10.172949144   6.287026853
##  [957]   6.941807150   1.070371909   0.175639601   6.155524505
##  [961]  14.649699626   6.013562173   5.829446662  -2.547893908
##  [965]   6.469545415   8.111610285  -4.004791612   4.494817269
##  [969]   3.210101148   7.407901447   2.988869539  10.549328526
##  [973]   5.517943326   5.327017829   7.395055723  -0.403991102
##  [977]  -3.581762641   6.042979448  10.990007932   2.554003650
##  [981]   6.444348572   1.273338853   4.061630394   0.639796443
##  [985]  -2.796711796   3.529272378  -1.739301363   5.183466604
##  [989]   5.288504405   5.897913860  11.088815623   4.136421705
##  [993]   6.083478740   0.738802369  -3.126176585  -3.360733898
##  [997]  -0.220005460  11.191613341   4.894870323   6.554129968

Vectorizing a Function

  • The mapply() function can be use to automatically "vectorize" a function.
  • It can be used to take a function that typically only takes single arguments and create a new function that can take vector arguments.

Here's an example of a function that computes the sum of squares \(\sum_{i=1}^n(x_i-\mu)^2/\sigma^2\).

sumsq <- function(mu, sigma, x) {
    sum(((x - mu)/sigma)^2)
}

This function takes a mean mu, a standard deviation sigma, and some data in a vector x.

In many statistical applications, we want to minimize the sum of squares to find the optimal mu and sigma. Before we do that, we may want to evaluate or plot the function for many different values of mu or sigma. However, passing a vector of mus or sigmas won't work with this function because it's not vectorized.

x <- rnorm(100)  ## Generate some data
sumsq(1:10, 1:10, x)  ## This is not what we want
## [1] 102.6366

Note that the call to sumsq() only produced one value instead of 10 values.

However, we can do what we want to do by using mapply().

mapply(sumsq, 1:10, 1:10, MoreArgs = list(x = x))
##  [1] 177.75073 114.48944 104.24053 101.14824  99.94315  99.41072  99.16312
##  [8]  99.05000  99.00502  98.99614

There's even a function in R called Vectorize() that automatically can create a vectorized version of your function. So we could create a vsumsq() function that is fully vectorized as follows.

vsumsq <- Vectorize(sumsq, c("mu", "sigma"))
vsumsq(1:10, 1:10, x)
##  [1] 177.75073 114.48944 104.24053 101.14824  99.94315  99.41072  99.16312
##  [8]  99.05000  99.00502  98.99614

Summary

  • The loop functions in R are very powerful because they allow you to conduct a series of operations on data using a compact form

  • The operation of a loop function involves iterating over an R object (e.g. a list or vector or matrix), applying a function to each element of the object, and the collating the results and returning the collated results.

  • Loop functions make heavy use of anonymous functions, which exist for the life of the loop function but are not stored anywhere

  • The split() function can be used to divide an R object in to subsets determined by another variable which can subsequently be looped over using loop functions.

Lab Session 2

In this lab, you will use the temperature data in four cities: Melbourne, Sydney, Brisbane and Cairns. You can download them from https://yanfei.site/docs/sc/data/temp.zip.

  1. Please make a function load.file() to read a .csv file and transform the first column (a character representing date and time) using as.POSIXlt into R time format.
  2. Then apply load.file() to each filename using lapply().
  3. How many rows of data are there for each city?
  4. What is the hottest temperature recorded by city?
  5. Estimate the autocorrelation function for each city.

References

Chapters 14, 15 and 18 of the book "R programming for data science".