Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205372

using apply within ifelse R data.table

$
0
0

I have the following data.table object:

USER    active  rate   day    # of elements by hour
4q7C0o  1         1.48  1       c(0, 0, 0, 0, 0, 0, 5, 98, 167, 211, 246)
2BrKY63 1         0.5   3       c(0, 0, 0, 0, 0, 0, 0, 5, 15, 24, 89, 187) 
3drUy6I 1         2.58  5       c(0, 0, 0, 0, 0, 0, 0, 0, 1, 112, 265, 309) 
G5ALtO  1         1.1   7       c(0, 0, 0, 0, 0, 0, 0, 2, 20, 153, 170)

Where each element of the column # of elements by hour is a list with varying length. I would like to apply the function pexp() to each element of each list (ex. pexp(0, rate = 1.48) to the first element of the first list and pexp(246, rate = 1.48) to the last element of the first list) and if a value less than 'x' occurs then it is displayed in a new column. Something like :

DT[, ifelse(any(lapply( of elements by hour, pexp, rate = rate) < x), 'no.usable','usable' )  ,]

However I don't know how could this be done in a short way in data.table.


Viewing all articles
Browse latest Browse all 205372

Trending Articles