Error: unexpected '}' : <p>I'm trying to generate a random data. Basically, I copied this code from the book, however it doesn't work for me. It works until it reaches the line stated in the warning:  </p>

<pre><code>Error: unexpected '}' in:
"+ this.seg[,j] &lt;- rnorm(segSize[i], mean=segMeans[i,j], sd=segSDs[i,j])
+ }"
</code></pre>

<p>The code looks as following:</p>

<pre><code>for (i in seq_along(segNames)) {
  + cat(i, segNames[i], "\n")
  +
    + # empty matrix to hold this particular segment’s data
    + this.seg &lt;- data.frame(matrix(NA, nrow=segSize[i], ncol=length(segVars)))
    +
      + # within segment, iterate over variables and draw appropriate random data
      + for (j in seq_along(segVars)) { # and iterate over each variable
        + if (segVarType[j] == "norm") { # draw random normals
          + this.seg[,j] &lt;- rnorm(segSize[i], mean=segMeans[i,j], sd=segSDs[i,j])
          + } else if (segVarType[j] == "pois") { # draw counts
            + this.seg[, j] &lt;- rpois(segSize[i], lambda=segMeans[i, j])
            + } else if (segVarType[j] == "binom") { # draw binomials
              + this.seg[, j] &lt;- rbinom(segSize[i], size=1, prob=segMeans[i, j])
              + } else {
                + stop("Bad segment data type: ", segVarType[j])
                + }
        + }
    + # add this segment to the total dataset
      + seg.df &lt;- rbind(seg.df, this.seg)
      + }
</code></pre>

<p>Can somebody explain why it stucks on that line and what has to be changed? Thanks! </p>
