[R] Function on an array
Barry King
barry.king at qlx.com
Wed Oct 8 12:54:03 CEST 2014
ex1 <- c('Y', 'N', 'Y')
ex2 <- c('Y', 'N', 'Y')
ex3 <- c('N', 'N', 'Y')
ex4 <- c('N', 'N', 'Y')
status <- array(NA, dim=3)
# I am trying to return 'Okay' if any of the values
# in a column above is 'Y' but I am not constructing
# the function corrrectly. Any assistance is
# greatly appreciated
status_fnc <- function(e){
if (e[ ,1] == 'Y' | e[ ,2] == 'Y' | e[ ,3] == 'Y' | e[ ,4] == 'Y'){
return('Okay')
} else return('Not okay')
}
status <- sapply(cbind(ex1, ex2, ex3, ex4), status_fnc)
[[alternative HTML version deleted]]
More information about the R-help
mailing list