[R] index instead of loop?
Rui Barradas
rui1174 at sapo.pt
Tue Mar 6 16:22:54 CET 2012
Hello,
> Just looking at this, but it looks like ix doesn't exist:
> sapply(1:length(inxlist), function(i) if(length(ix[[i]]))
> fin1[ix[[i]], tkr + 1] <<- ua[i, tkr])
>
> Trying to sort it out now.
Right, sorry.
I've changed the name from 'ix' to 'inxlist' to make it more readable just
before posting.
And since the object 'ix' still existed in the R global environment it
didn't throw an error...
Your correction in the post that followed is what I meant.
Correction (full loop, tested):
for(tkr in 1:ncol(ua)){
x <- c(rd1[, tkr], as.Date("9999-12-31"))
ix <- lapply(1:nr, function(i)
which(x[i] <= dt1 & dt1 < x[i + 1]))
sapply(1:length(ix), function(i)
if(length(ix[[i]])) fin1[ix[[i]], tkr + 1] <<- ua[i, tkr])
}
Rui Barradas
--
View this message in context: http://r.789695.n4.nabble.com/index-instead-of-loop-tp4447672p4450186.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list