On Mon, Jan 19, 2009 at 9:08 PM,  <rkevinbur...@charter.net> wrote:
> Sorry I didn't give the proper initialization of j. But you are right j 
> should also be an array of 5. So x[j + 5] would return 5 values.
>
> So if the array returned from 'ifelse' is the same dimention as test (h), 
> then are all the values of h being tested? So since h as you say has no 
> dimensions is the test only testing h[1]? Again it seems that if all of the 
> elements of h are tested (there are 5 elements) and each element produces an 
> array of 5 the resulting array should be 25.
>
> Kevin
>

ifelse returns values "row-by-row", so to speak. in this case, it will
return the vector:
c(x[j+2][1] , x[j+2][2] , x[j+2][3] , x[j+2][4] , x[j+2][5]).

If you instead write:

h<-numeric(5)
 j<-1:5
p <- 1:5
x<-1:1000
ifelse(h == 0,list(x[j+2]), 1:5)

,you get what you expected, since ifelse recycles the second argument
if necessary.

Regards,

Gustaf

-- 
Gustaf Rydevik, M.Sci.
tel: +46(0)703 051 451
address:Essingetorget 40,112 66 Stockholm, SE
skype:gustaf_rydevik

______________________________________________
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