Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Problem is that the ksmooth function will return a list, and those lists are saved as that by rollaplly. By the way, I don't think you even want to use rollaplly, as that does not do this for each date but "rolls" over the dataframe. I believe from your explanation that is not the desired behaviour.</p> <p>I couldn't really work it out using a zoo object, as that one is quite restrictive. Maybe somebody else will show you that. You can construct that dataframe using the <code>ddply</code> function from the <code>plyr</code> package :</p> <pre><code>tt &lt;- ddply(test,.(Date), function(x) { as.data.frame(ksmooth(x$return,x$price,"normal",bandwidth=2,n.points=50)) }) </code></pre> <p>tt can then be transformed to a zoo object, using</p> <pre><code>tt2 &lt;- zoo(tt, as.POSIXct(tt$Date) + 1:50) </code></pre> <p>Alternatively, you could do it by hand using a bit of list manipulation. again, the resulting tt can be converted by the line above to a zoo object.</p> <pre><code>tt &lt;- split(test,test$Date) tt &lt;- lapply(tt,function(x){ as.data.frame(ksmooth(x$return,x$price,"normal",bandwidth=2,n.points=50)) }) tt &lt;- do.call(rbind,tt) names(tt) &lt;- c("return","price") tt$Date &lt;- as.Date(gsub("\\.\\d+","",rownames(tt))) </code></pre> <p>Mind you, I used <code>read.table()</code> to construct test :</p> <pre><code>zz &lt;- textConnection( "Date , return , price , vol 20100902 , 0.3 , 15 , 8.5 20100902 , 0.4 , 17 , 8.6 20100902 , 0.6 , 19 , 8.7 20100903 , 0.2 , 13 , 8.2 20100903 , 0.4 , 17 , 8.6 20100903 , 0.8 , 21 , 9.0" ) test &lt;- read.table(zz,header=T,sep=",") test$Date &lt;- as.Date(as.character(test$Date),format="%Y%m%d") close(zz) </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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