r - conditional mean of a column based on another column in the same xts object -


i have following xts object = mydata:

row.names   ret   flag 8/1/2014    10     1 8/4/2014    12     3 8/5/2014    -15    2 8/6/2014    05     1 8/7/2014   -06     2 

i find mean of returns have flag =1, flag = 2, flag = 3

this have:

 g.rt= matrix(0, nrow = 3)  (i in 1:3)   {   rt[i]=sapply(x=1:nrow(mydata), fun=function(x)    {mean(mydata[which(mydata$flag == i),1])})   } 

although works, warning message

    "in g.rt[5] = sapply(x = 1:nrow(tprt), fun = function(x) { :     number of items replace not multiple of replacement length" 

i not sure implications going have. can please @ code , see doing wrong?


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -