[R] Seeking help with an apparently simple recoding problem

From: Greg Blevins <GBLEVINS_at_marketsolutionsgroup.com>
Date: Wed 24 Aug 2005 - 01:12:33 EST


Hello,

I have struggled, for longer than I care to admit, with this seemingly simple problem, but I cannot find a solution other than the use of long drawn out ifelse statements. I know there has to be a better way. Here is stripped down version of the situation:

I start with:

a <- c(1,0,1,0,0,0,0)
b <- c(1,1,1,1,0,0,0)
c <- c(1,1,0,1,0,0,0)

rbind(a,b,c)
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
a 1 0 1 0 0 0 0
b 1 1 1 1 0 0 0
c 1 1 0 1 0 0 0

I refer to column 3 as the target column, which at the end of the day will be NA in all instances.

The logic involved:

  1. If columns 2, 4 thru 7 do NOT include at least one '1', then recode columns 2 thru 7 to NA and recode column 1 to code 2.
  2. If columns 2, 4 thru 7 contain at least one '1', then recode column 3 to NA.

Desired recoding of the above three rows:
[,1] [,2] [,3] [,4] [,5] [,6] [,7]

a    2    	NA    	NA    	NA   	NA   	NA    	NA
b    1    	1    	NA    	1   	0   	0    	0
c    1    	1    	NA    	1   	0   	0    	0

Thanks you.

Greg Blevins
The Market Solutions Group, Inc.

Windows XP, Version 2.1.1



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Aug 24 01:21:40 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:55 EST