Note that there are some explanatory texts on larger screens.

plurals
  1. POR error: Wrong length for a vector, should be 2
    primarykey
    data
    text
    <p>Here is a gist of what I want to do:</p> <p>I've got 2 data frames:<br> x (id is unique)</p> <pre><code>id timestamp 282462839 2012-12-05 10:55:00 282462992 2012-12-05 12:08:00 282462740 2012-12-05 12:13:00 282462999 2012-12-05 12:48:00 </code></pre> <p>y (id is not unique)</p> <pre><code>id value1 value2 282462839 300 100 282462839 300 200 282462839 400 300 282462999 500 400 282462999 300 150 </code></pre> <p>I also have a function myfunc(id,pvalue) that computes something and returns one of the value2 values depending on pvalue and other value1s (more complicated than just pvalue==value1)</p> <p>I want to create a 3rd column for x that contains the corresponding computed myfunc(id,pvalue), where pvalue is an integer that is constant(say 20). </p> <p>so in essence, I want to do this:</p> <pre><code>x$t20 &lt;- myfunc(x$id,20) </code></pre> <p>I tried using lappy and sapply this way:</p> <pre><code>x$t20 &lt;- sapply(as.vector(x$id),myfunc,pvalue=20) </code></pre> <p>I tried using lapply and without the as.vector as well, but I kept getting this error:</p> <pre><code>Error in .pointsToMatrix(p2) : Wrong length for a vector, should be 2 </code></pre> <p>It works when I just give mean where it just replicates $id in $t20.</p> <p>How do I do this?</p> <p>EDIT 1: Here's a skeleton of myfunc:</p> <pre><code>myfunc &lt;- function(xid,pvalue) { result &lt;- subset(y,id==xid) retVal &lt;- -1 if(nrow(result) &lt; 12){ return(NaN) } for(i in (1:nrow(result))){ #code to process result } return(retVal) } </code></pre>
    singulars
    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. 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