R Programming: Predicting Outliers

0 votes

I'm creating a R program for predicting the outliers in my data set and I'm trying to cut each row containing outliers from my existing data set and putting it in another file.

This is my code:

library(outliers)
for(i in 2:25)
{
  outlier[i]=outlier(Dummy[i], logical=TRUE)
  find_outlier[i]=which(outlier[i]==TRUE,arr.ind=TRUE)
  new_outlier[i]=Dummy[find_outlier[,i]]
}

When I run this code for one variable it works properly. But when I embed this code into a loop it does not work. 

What is the problem here?

Jan 28 in Data Analytics by Tyrion anex
• 8,270 points
73 views

1 answer to this question.

0 votes

You can remove outliers without a loop, try this:

Student <- c("A", "B", "C", "D", "E")
Test1 <- c(45, 36, 41, 42, 15)
Test2 <- c(47, 42, 38, 34, 44)
Test3 <- c(39, 41, 35, 21, 48)
Test4 <- c(13, 45, 42, 35, 37)
Test5 <- c(36, 38, 42, 14, 47)
Dummy <- data.frame(Student, Test1, Test2, Test3, Test4, Test5)
out <- outlier(Dummy[,2:6], logical=TRUE)
out <- cbind(FALSE, out)
# Actual outlier values
Dummy[which(out[,], TRUE)]
# Row and column numbers of the outliers
which(out[,], TRUE)
answered Jan 28 by Sophie may
• 9,530 points

Related Questions In Data Analytics

0 votes
1 answer

Removing outliers from a box-plot - ggplot2 - R

You just have to add 'outlier.shape=NA' inside ...READ MORE

answered May 31, 2018 in Data Analytics by Bharani
• 4,550 points
2,800 views
0 votes
2 answers

What are the rules to define a variable name in R programming language?

The same rules almost follow for all ...READ MORE

answered Aug 26 in Data Analytics by anonymous
• 25,820 points
85 views
0 votes
1 answer

Why should I adopt R programming

R Programming is the best mechanism for ...READ MORE

answered Oct 29, 2018 in Data Analytics by Maverick
• 10,040 points
24 views
0 votes
2 answers

Error: could not find function - R Programming

Yes, Just like @Maverik said, It happens ...READ MORE

answered Aug 22 in Data Analytics by anonymous
• 25,820 points
2,396 views
+1 vote
2 answers
0 votes
1 answer

R programming logic

Use gsub to match the substring that we want ...READ MORE

answered Nov 16, 2018 in Data Analytics by Maverick
• 10,040 points
28 views
0 votes
1 answer
+4 votes
2 answers
0 votes
1 answer

R Programming: matrices

Try this, It will test if a matrix ...READ MORE

answered Dec 17, 2018 in Data Analytics by Sophie may
• 9,530 points
29 views
0 votes
1 answer

R programming: Unexpected symbol error

Format your code this way: myfunction <- function() ...READ MORE

answered Dec 17, 2018 in Data Analytics by Sophie may
• 9,530 points
232 views