[R] another index question

From: Bob Green <bgreen_at_dyson.brisnet.org.au>
Date: Sat, 29 Dec 2007 22:38:54 +1000

I am hoping for some advice regarding another index problem. The code below is intended to assign a value of 'V' if values on certain variables are >= 1, assign a value of 'N' if values on certain variables are >= 1 on other variables and assign a 'O' if values on any variable which have a value <= 0.

The outcome of this code is to assign a single 'O'. Clearly I have made a mistake somewhere.

pre_ <- new <- rep(0, nrow(reoffend))
> pre_ <- new[reoffend$pre01111 | reoffend$pre012 |
reoffend$pre013>= 1] <-'V'
> pre_ <- new[reoffend$pre02111>=1 | reoffend$pre02114>=1 |
reoffend$pre2029>=1 | reoffend$pre0212>=1 | reoffend$pre0211>=1]<- 'V'
> pre_ <- new[reoffend$pre03a >=1 | reoffend$pre0311 >=1 |
reoffend$pre0312 >=1| reoffend$pre03 >= 1] <- 'V'
> pre_ <- new[reoffend$pre04>=1 | reoffend$pre05 >=1 |
reoffend$pre06 >=1] <- 'V'
> pre_ <- new[reoffend$pre07 >=1 | reoffend$pre08 >=1 |
reoffend$pre09 >=1| reoffend$pre10 >= 1 |reoffend$pre11 >=1 | reoffend$pre12 >=1 | reoffend$pre13 >=1| reoffend$pre14 >= 1 |reoffend$pre15 >=1| reoffend$pre16 >= 1 ] <- 'N'
> pre_ <- new[reoffend$pre01111 | reoffend$pre012 | reoffend$pre013<=0] <-'O'
> pre_ <- new[reoffend$pre02111<=0 | reoffend$pre02114<=0 |
reoffend$pre2029<=0 | reoffend$pre0212<=0 | reoffend$pre0211 <=0] <-'O'
> pre_ <- new[reoffend$pre03a | reoffend$pre0311 | reoffend$pre0312
| reoffend$pre03<=0] <- 'O'
> pre_ <- new[reoffend$pre04 | reoffend$pre05 | reoffend$pre06<=0] <- 'O'
> pre_ <- new[reoffend$pre07| reoffend$pre08 | reoffend$pre09 |
reoffend$pre10 |reoffend$pre11 | reoffend$pre12 | reoffend$pre13 | reoffend$pre14 |reoffend$pre15 | reoffend$pre16<= 0 ] <- 'O'
>

Secondly, once this is resolved I was hoping to change the prefix "pre_)" to "mhc_", repeat this code and join the pre_ and mhc_ variables - so the new variable would have values such as 'VO" or 'NV' etc. I was hoping something like : total <- c(pre_ , mhc_) would do this or am I misguided.

Any assistance is much appreciated,

Bob Green



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. Received on Sat 29 Dec 2007 - 12:37:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 29 Dec 2007 - 14:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.