Re: [R] ifelse help

2012-07-10 Thread Jeff Newmiller
You failed to tell us any of: the actual code you used, the data you were working with, or the actual error you got. Your "pseudo-code" looks okay to me, so I suggest you read the Posting Guide and try again. (Anything other than a complete reproducible example of your problem is unlikely to eli

Re: [R] ifelse help

2012-07-10 Thread Jeff
At 07:41 PM 7/10/2012, you wrote: Seems to work for me: > x <- data.frame(old1 = sample(c(1,2,8), 10, TRUE), old2 = 1:10) > x$new <- ifelse(x$old1 == 8, 1, x$old2) > x Thanks Jim and Dan. The problem ended up with a missing values issue that threw me off. When your post confirmed that my co

Re: [R] ifelse help

2012-07-10 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Jeff > Sent: Tuesday, July 10, 2012 5:26 PM > To: r-help > Subject: [R] ifelse help > > > I'm sure this is easy, but I'm new to R and can't find any example of > the following.

Re: [R] ifelse help

2012-07-10 Thread jim holtman
Seems to work for me: > x <- data.frame(old1 = sample(c(1,2,8), 10, TRUE), old2 = 1:10) > x$new <- ifelse(x$old1 == 8, 1, x$old2) > x old1 old2 new 1 11 1 2 22 2 3 23 3 4 84 1 5 15 5 6 86 1 7 87 1 8 28 8 9 2

Re: [R] ifelse help?

2009-01-20 Thread Petr PIKAL
r-help-boun...@r-project.org napsal dne 19.01.2009 21:08:59: > 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

Re: [R] ifelse help?

2009-01-20 Thread Gustaf Rydevik
On Mon, Jan 19, 2009 at 9:08 PM, 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

Re: [R] ifelse help?

2009-01-19 Thread rkevinburton
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

Re: [R] ifelse help?

2009-01-19 Thread Charles C. Berry
On Mon, 19 Jan 2009, rkevinbur...@charter.net wrote: I am having a hard time understanding what is happening with ifelse. Let me illustrate: h <- numeric(5) p <- 1:5 j <- floor(j) And j is 0:4 + epsilon , where 0 <= epsilon < 1, evidently. x <- 1:1000 ifelse(h == 0, x[j+2], 1:5) [1] 2 3 4