[R] Help for i-else iwth more than one alternative

MacQueen, Don macqueen1 at llnl.gov
Thu Oct 16 21:09:39 CEST 2014


If I understand what you¹re trying to do, then I believe this will do the
same as your little loop:

  opt.fc <- fc
  opt.fc[rmax < 0.1] <- fc1[rmax < 0.1]

(this is an example of vectorization, and it¹s fundamental to how R works
and the power of R)

Then to extend it, use the same method

  opt.fx[ {some expression} ] <- fc2[ {some expression} ]

But I have no idea what {some expression} should be. Perhaps it has
something to do with the maximized r squared values, but I can¹t tell from
what you¹ve said. In any case, the {some expression} has to result in a
logical vector of the same length as the others (373 in your example).

Hope this helps.

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 10/16/14, 8:51 AM, "moeby" <fabian_schlegel at hotmail.com> wrote:

>I try to run an if-else command line where the else argument should be the
>corresponding value of the pmax command.
>
>#####################
>#opt.fc is the optimal forecast
>#rmax is the vector of the maximized r squared from pmax-command of 2 data
>sets containing r squares
>#fc1 are the estimates of a specific forecast model (e.g. AR1)
>#fc are the estimates of a specific forecast model, namely the Benchmark
>(e.g. mean)
>
>opt.fc <- as.numeric(373) #data length is 373
>for (x in 1:373)
>{
>if (rmax[x] < 0.1)
>opt.fc[x] <- fc[x] #if rmax smaller than the value 0.1 the forecast of the
>benchmark should be used.
>else
>opt.fc[x] <- fc1[x] #else the forecast of fc model should be used.
>}
>So far, so easy.
>
>How can I compute the opt.fc when I have more than one alternative
>forecast
>model, let's say fc2 and fc3.
>In Addition, I want to use the values from the forecast model where the
>values of the corresponding r squared are maxed (pmax(fcr1,fcr2,fcr3...)
>..... :(
>
>any ideas?
> 
>Thank you very much in advance.
> 
> 		 	   		  
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Help-for-i-else-iwth-more-than-one-alternati
>ve-tp4698410.html
>Sent from the R help mailing list archive at Nabble.com.
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at 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.



More information about the R-help mailing list