Hello, Mr Dalgaard: you're right about the problem.
"Works for me, so there's something you're not telling us.... Possibly that x is not a vector (a data frame, maybe?)." the mistake message is below: Error in if (track01[i] > 1) track01[i] <- 1 : missing value where TRUE/FALSE needed the track01 above is my data, I've used a rnorm(500) data series instead, and the code works!! One thing I do know is that my "track01" data has NaN data. So I guess the system can not perform the code " if (track01[i] > 1)" when track01[i]=NaN, or the result is missing value, thus it need a TRUE/FALSE is there any command to replace the "NaN" value with 1 in an efficient way? Saji ----- ------------------------------------------------------------------ Saji Ren from Shanghai China GoldenHeart Investment Group ------------------------------------------------------------------ -- View this message in context: http://r.789695.n4.nabble.com/How-to-perform-a-substitution-in-a-loop-tp2325048p2325193.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.