title: Recode each element in an array list variable using for loop in R
body: <p>I am new to R and i've been stuck on this.  I have a data set below wherein I created a new array list variable called 'amountOfTxn_array' that contains three numeric values in sequential order.  These are amounts of transactions taken from Jan to Mar. My objective is to create new variables from this array list that iterate each data elements in the 'amountOfTxn_array'. </p>
  
  <pre><code>&gt; head(myData_05_Array)
  Index   accountID   amountOfTxn_array
  1:00    8887    c(36.44, 75.00,185.24)
  2:00    13462   c(639.45,656.10,237.00)
  3:00    47249   c(0,  24, 2012)
  4:00    49528   c(1189.20,2326.26,1695.89)
  5:00    57201   c(24.67, 0.00, 0.00)
  6:00    57206   c(0.00, 661.98,2957.68)
  </code></pre>
  
  <blockquote>
    <p>str(myData_05_Array)
    Classes ‘data.table’ and 'data.frame':  3176 obs. of  4 variables:
     $ accountID         : int  8887 13462 47249 49528 57201 57206 58522 79073 80465 81032 ...
     $ amountOfTxn_200501: num  36.4 639.5 0 1189.2 24.7 ...
     $ amountOfTxn_200502: num  75 656 24 2326 0 ...
     $ amountOfTxn_200503: num  185 237 2012 1696 0 ...
     $ amountOfTxn_array :List of 3176</p>
  </blockquote>
  
  <p>Also, an example code for creating a new variable is provided below wherein I would like to tag 1 if a value in the array is greater than 100 and 0 else.  When I ran the example code, I am getting "Error: (list) object cannot be coerced to type ‘double’ error.   May I ask for a solution for this.  I would highly appreciate any response.
  Thanks!</p>
  
  <pre><code>&gt; for(i in 1:3)
  + {  
  +   if(myData_05_Array$amountOfTxn_array[i] &gt; 100){
  +     myData_05_Array$testArray[i] &lt;- 1
  +   }
  +   else{
  +     myData_05_Array$testArray[i] &lt;- 0
  +   }
  + }
  </code></pre>
  
  <blockquote>
    <p>Error: (list) object cannot be coerced to type 'double'</p>
  </blockquote>
  
  <p>What I am expecting as the output is as follows:
  amountOfTxn_testArray
  c(0, 0, 1)
  c(1, 1, 1)
  c(0, 0, 0)
  c(1, 1, 1)
  c(0, 0, 0)
  c(0, 1, 1)</p>