[R] another index question
Bob Green
bgreen at dyson.brisnet.org.au
Sat Dec 29 13:38:54 CET 2007
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
More information about the R-help
mailing list