On 17/08/2009 10:22 AM, Lana Schaffer wrote:
Hi,
Can someone suggest an efficient way to substitute a vector/matrix
which contains 1's and 0's to P's and A's (resp.)?

x[x == 1] <- "P"
x[x == "0"] <- "A"

(I added the quotes around 0 on the second line because the first line changed x to a character vector. This isn't necessary, "0" == 0 comes out TRUE, but I think it is clearer.)

Duncan Murdoch

______________________________________________
R-help@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.

Reply via email to