Saji Ren wrote:
> 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?

Usually, you'd safeguard the if with "if (is.na(x[i]) || x[i] > 1)..."
or "if (!is.na(...) && ...)", depending on what you want.

BTW, notice also that pmin has an na.rm argument.

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd....@cbs.dk  Priv: pda...@gmail.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.

Reply via email to