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,700 points
1,063 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
• 10,620 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,660 points
24,838 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
• 33,030 points
15,176 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,840 points
846 views
+3 votes
2 answers

Error: could not find function - R Programming

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

answered Aug 23, 2019 in Data Analytics by anonymous
• 33,030 points
33,768 views
+10 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 9, 2018 in Data Analytics by Abhi
• 3,720 points
1,665 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,840 points
765 views
0 votes
1 answer
+1 vote
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
• 10,620 points
763 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
• 10,620 points
3,285 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP