Assignment 11
## Original Code
tukey_multiple <- function(x) {
outliers <- array(TRUE,dim=dim(x))
for (j in 1:ncol(x))
{
outliers[,j] <- outliers[,j] && tukey.outlier(x[,j])
}
outlier.vec <- vector(length=nrow(x))
for (i in 1:nrow(x))
{ outlier.vec[i] <- all(outliers[i,]) } return(outlier.vec) }
#DeBugged Code
tukey_multiple <- function(x) {
outliers <- array(TRUE, dim=dim(x))
for (j in 1:ncol(x)) {
outliers[,j] <- outliers[,j] && #tukey.outlier(x[,j]) ## tukey.outlier does not exist
}
outlier.vec <- vector(length=nrow(x))
for (i in 1:nrow(x)) {
outlier.vec[i] <- all(outliers[i,])
}
return(outlier.vec)
}
To start debugging, I pasted the code into RStudio to see what kind of error it would throw. The syntax was wrong with the alignment of certain brackets and parentheses. I then realized that the tukey.outlier function was not defined/did not exist which is why it was throwing more errors.
Comments
Post a Comment