I currently have a line of code set up to sum each row/date of a xts object, where value for each data point = 1:
universe.rt=sapply(X=2:nrow(rt),FUN=function(x){sum(rt[x,which(live[x,]==1)])/count[x]})
I want to change the code such that instead of summing up all points in a row where value = 1, I want to sum all points in a row where value is NOT NA:
universe.rt=sapply(X=2:nrow(rt),FUN=function(x){sum(rt[x,which(live[x,]==!is.na)])/count[x]})
I can't get the syntax right.