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, 2019 in Data Analytics by Tyrion anex
• 8,360 points
113 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, 2019 by Sophie may
• 9,940 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,560 points
7,640 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, 2019 in Data Analytics by anonymous
• 32,440 points
317 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,800 points
46 views
0 votes
2 answers

Error: could not find function - R Programming

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

answered Aug 22, 2019 in Data Analytics by anonymous
• 32,440 points
10,895 views
+9 votes
3 answers

Which is a better initiative to learn data science: Python or R?

Well it truly depends on your requirement, If ...READ MORE

answered Aug 8, 2018 in Data Analytics by Anmol
• 3,680 points
125 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,800 points
51 views
0 votes
1 answer
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,940 points
49 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,940 points
642 views