Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have not provided a reproducible example, so i'm guessing a little: but it seems that the problem is that <code>example1</code> is made up of factors. </p> <p>Here's a basic guess at <code>example1</code></p> <pre><code>example1 &lt;- as.factor(LETTERS[1:9]) </code></pre> <p>when you print your <code>factor1</code> you probably see something like the following:</p> <pre><code>R&gt; example1 [1] A B C D E F G H I Levels: A B C D E F G H I </code></pre> <p>Now if we try and replace any item with a non-factor (something not listed in <code>levels</code> above), we will get the following error (which is similar to yours): </p> <pre><code>R&gt; example1[8] &lt;- "KK" Warning message: In `[&lt;-.factor`(`*tmp*`, 8, value = "KK") : invalid factor level, NA generated </code></pre> <p>but note that you could make a substitution of one listed factor for another -- meaning that <code>example1[8] &lt;- "A"</code> is valid. </p> <p>My guess is that you don't want factors -- you want characters. So you need to coerce <code>example1</code> to character. Do this as follows</p> <pre><code>R&gt; example1.ch &lt;- as.character(example1) </code></pre> <p>No your substitution will work:</p> <pre><code>R&gt; example1.ch[8] &lt;- 'kk' R&gt; example1.ch [1] "A" "B" "C" "D" "E" "F" "G" "kk" "I" </code></pre> <p>In general, you can use the command <code>str()</code> to learn about what your data object is comprised of -- which will help when you get odd errors like this one. </p> <pre><code>R&gt; str(example1) Factor w/ 9 levels "A","B","C","D",..: 1 2 3 4 5 6 7 1 9 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload