Reputation: 49
fct<- function(x){volume03[[x]][which(is.na(last03[[x]]))]<- NA}
lapply(1:length(volume03, fct)
I want to set all of those numbers within volume03 to NA, which are NA in last03. However, R is returning a list of only NAs.
Why I am trying to do that: The data is stock data (zoo series) -
volume[[1]][1]
returning data for company 1 on day one. Some of the data is zero, which should not be the case.
Upvotes: 0
Views: 89
Reputation: 66
Or, you can just do
for (i in 1:length(volume03)) volume03[[i]][is.na(last03[[i]])] <- NA
Indices can be easily operated explicitly:
l=c(NA, 1, 2);k=c(3, 5, 6)
> i.l=is.na(l)
> i.l
[1] TRUE FALSE FALSE
> k[i.l]=NA
> k
[1] NA 5 6
> l=c(NA, 1, 2);k=c(3, 5, 6)
> k[is.na(l)]=NA
> k
[1] NA 5 6
Upvotes: 1