On Jul 20, 2010, at 1:14 PM, Heiman, Thomas J. wrote:
Hi Y'all,
I have some data in a table with 2 columns. There are two values:
"Reduction" and "No Reduction. " I am trying to make a new variable
change which recode the combinations from column 1 and 2 into a
single number. Here is a snippet from the table:
[1,] "NoReduction" "NoReduction"
[2,] "Reduction" "Reduction"
[3,] "NoReduction" "NoReduction"
[4,] "NoReduction" "NoReduction"
[5,] "Reduction" "Reduction"
[6,] "Reduction" "Reduction"
[7,] "Reduction" "Reduction"
[8,] "NoReduction" "NoReduction"
[9,] "NoReduction" "NoReduction"
[10,] "NoReduction" "NoReduction"
This is the code that I have written so far..
for (i in 1:nrow(change20082009))
if(change20082009[i,1]=='No Reduction' & change20082009[i,2]=='No
Reduction') "){change20082009[i,3] <- 1} else
if(change20082009[i,1]=='No Reduction' & change20082009[i,
2]=='Reduction'){change20082009[i,3] <- -1} else
if(change20082009[i,1]=='Reduction' & change20082009[i,2]=='No
Reduction') {change20082009[i,3] <- 2} else
if(change20082009[i,1]=='Reduction' & change20082009[i,
2]=='Reduction') {change20082009[i,3] <- 0}
)
I can't seem to get the code above to work..Any suggestions (I am
sure it is really basic)? Is there a better way to do this?
You are going to have a problem if you think that "NoReduction" == 'No
Reduction'
--
David
______________________________________________
[email protected] 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.