I have an xts object that contain several columns with one numeric values per row and I need to select the name and the value of columns where value is greater than 0 for the day n-1.
Object1 <- colnames(xxx)[apply(xxx[Sys.Date()-1],1,which.max)]
I use this to select the name of the column for the row where value > 0 but it works only if there is one column. My xts object can have several.
Please find how the xts object xxx
looks like :
AAAAAA BBBBBB CCCCCC DDDDDD EEEEEE FFFFFF GGGGGG HHHHHH IIIIII JJJJJJ KKKKKK LLLLLL MMMMMM NNNNNN OOOOOO PPPPPP
2015-02-25 0 0 0.00 0 0 0 0 0.33 0.00 0 0 0 0 0.33 0.33 0
2015-02-26 0 0 0.33 0 0 0 0 0.33 0.00 0 0 0 0 0.33 0.00 0
2015-02-27 0 0 0.33 0 0 0 0 0.33 0.00 0 0 0 0 0.33 0.00 0
2015-03-02 0 0 0.00 0 0 0 0 0.33 0.33 0 0 0 0 0.33 0.00 0
2015-03-03 0 0 0.00 0 0 0 0 0.33 0.33 0 0 0 0 0.33 0.00 0
2015-03-04 0 0 0.00 0 0 0 0 0.33 0.33 0 0 0 0 0.33 0.00 0
I would like to retieve for day n-1 an object like this :
>Object
HHHHHH IIIIII NNNNNN
2015-03-03 0.33 0.33 0.33
Or it would be even better if it could be one row per line:
>Object
2015-03-03 HHHHHH 0.33
2015-03-03 IIIIII 0.33
2015-03-03 NNNNNN 0.33
I have tried with apply
and which(xxx[Sys.Date()-1]>0
but unfortunatly it returns TRUE of FALSE for each column.
Thank you