As you're well aware, we started out with the following 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) }
I set X equal to 5 and input the code into R Studio. This is the error message I received:
" for (i in 1:nrow(x))
{ outlier.vec[i] <- all(outliers[i,]) } return"
How disappointing! I actually did a lot of research at this point into the error itself, looking over several entirely unhelpful posts from Stack Overflow. The good news is that in doing that kind of digging/browsing for information, you often learn about other aspects that maybe weren't part of the assignment. I don't mind this phase of research because it sparks my interest and keeps me engaged.
After awhile I decided to clean up my 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)
This code yields no errors in R Studio and so I can only assume the bug was resolved by making sure everything was on its own line where appropriate. The brackets were crowding other lines of code and I think this is what may have been causing the error in the first place. If there is something more that should have been done, please let me know! I was sort of expecting to see some kind of result in R Studio other than a simple return without an error message, but I'm not sure what else I may be missing.
No comments:
Post a Comment