re-coding based on entry position

21 views Asked by At

For each row in my data, I want to re-code all "NA" after the last "1" or "0" different from "NA" before the last "1" or "0". Here is an example:

r <- matrix(c(1,1,1,1,1, 1,1,1,1,0, 1,NA,1,1,1, 1,0,1,1,1, 1,1,1,NA,NA, 1,1,0,NA,1, 1,1,NA,NA,NA, 1,NA,NA,NA,NA),ncol=5, nrow=8, byrow=T,
dimnames= list(c("r1", "r2","r3","r4","r5","r6","r7","r8"), c("Item1", "Item2", "Item3", "Item4", "Item5")))

Can anyone show me with a simple example?

0

There are 0 answers