I have two arrays "begin" and "end_a" which contain some integer indices, except that some of the entries in "end_a" are NA
.
And panelDataset
is a matrix which contains the data. I want to take the means of the rows of panelDataset
corresponding to non-NA entries of begin and end_a.
I have this working in serial fashion and it works fine, but when I tried to vectorize it as follows
switch_mu=ifelse(!is.na(end_a),mean(panelDataset[begin: end_a,4]),NA)
It gives an error: Error in begin:end_a : NA/NaN argument.
When I check the entries of end_a separately for NA
s using is.na(end_a)
, it does show the correct entries of the array as NA
. So, that is not an issue.
I know I am missing something trivial. Any thoughts?