Skip to content
Prev 171459 / 398503 Next

array manipulation simple questions

2009/2/23 ???????? ??????? <bleonidas25 at yahoo.gr>:
(a>5)+0

# or

out <- as.numeric(a > 5)
if (is.matrix(a)) out <- matrix(a, 1)
out
# return c(4, 5, 2) or x
f <- function(x) if (x==2) c(4:5, x) else x

# apply f to each element and
# if a is a matrix make output a matrix too

out <- unlist(sapply(a, f))
if (is.matrix(a)) out <- matrix(out, nrow(a))
out
which(a == 2)