Tuesday, 10 September 2013

How to efficiently turn a particular element of each list in a list into a vector?

How to efficiently turn a particular element of each list in a list into a
vector?

My current way is
coalesce <- function(x){
if (is.null(x)) NA else x
}
data[,b:=sapply(JSON, function(x) coalesce(x$a))]
JSON is a list of lists, each list may contain a which I would like to
grab. If a doesn't exist, NA is returned.
My Rprof tells me the majority time spent lies in sapply and Fun and
coalesce.
I am wondering if there is any way to improve it?

No comments:

Post a Comment