Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9207141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:19:28+00:00 2026-06-18T00:19:28+00:00

I have number of different tables and I want to write a function in

  • 0

I have number of different tables and I want to write a function in R in which:

Table No.1:

          coordinates var1.pred  var1.var observed    residual      zscore fold
1  (2579410, 1079720)  5.057024 0.4325275    5.468  0.41097625  0.62489903    1
2  (2579330, 1079730)  5.329797 0.3945041    4.498 -0.83179667 -1.32431534    2
3  (2579260, 1079770)  4.788211 0.5576228    5.114  0.32578861  0.43628035    3
4  (2579930, 1080030)  5.067753 0.4972365    4.764 -0.30375347 -0.43076434    4
5  (2579700, 1079770)  5.116632 0.5792768    4.626 -0.49063190 -0.64463327    5
6  (2579540, 1079640)  4.865667 0.6122453    6.522  1.65633254  2.11682434    6
7  (2579860, 1079880)  5.139779 0.4655840    4.856 -0.28377887 -0.41589245    7

if the value of ‘observed’ lay ouside the tolerance of two folllowing values label it as outlier:

var1.pred+(1.96*sqrt(var1.var))
var1.pred-(.96*sqrt(var1.var))

in other words:

      if   
   var1.pred-(1.96*sqrt(var1.var)) < 'observed' <  var1.pred-(1.96*sqrt(var1.var))

results normal otherwise results outlier.

Moreover, names of the columns are the same and table names are 1,2,3 …. .

 dat <- structure(list(coordinates = structure(c(3L, 2L, 1L, 7L, 5L,                                
     4L, 6L), .Label = c("(2579260, 1079770)", "(2579330, 1079730)",                                
     "(2579410, 1079720)", "(2579540, 1079640)", "(2579700, 1079770)",                              
     "(2579860, 1079880)", "(2579930, 1080030)"), class = "factor"),                                
         var1.pred = c(5.057024, 5.329797, 4.788211, 5.067753, 5.116632,                            
         4.865667, 5.139779), var1.var = c(0.4325275, 0.3945041, 0.5576228,                         
         0.4972365, 0.5792768, 0.6122453, 0.465584), observed = c(5.468,                            
         4.498, 5.114, 4.764, 4.626, 6.522, 4.856), residual = c(0.41097625,                        
         -0.83179667, 0.32578861, -0.30375347, -0.4906319, 1.65633254,                              
         -0.28377887), zscore = c(0.62489903, -1.32431534, 0.43628035,                              
         -0.43076434, -0.64463327, 2.11682434, -0.41589245), fold = 1:7), .Names = c("coordinates", 
     "var1.pred", "var1.var", "observed", "residual", "zscore", "fold"                              
     ), row.names = c(NA, -7L), class = "data.frame")  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:19:29+00:00Added an answer on June 18, 2026 at 12:19 am

    This should work:

    dat$outlier = with(as.data.frame(dat), 
                       ifelse(observed > (var1.pred + (.95*var1.var)) | # | = OR
                              observed < (var1.pred - (.95*var1.var)),
                 "outlier", "normal"))
    

    My code is a bit different from your description, as I check if the value is outside the range, not if it is inside. The above run on your example code:

    > dat
             coordinates var1.pred  var1.var observed   residual     zscore fold
    1 (2579410, 1079720)  5.057024 0.4325275    5.468  0.4109762  0.6248990    1
    2 (2579330, 1079730)  5.329797 0.3945041    4.498 -0.8317967 -1.3243153    2
    3 (2579260, 1079770)  4.788211 0.5576228    5.114  0.3257886  0.4362803    3
    4 (2579930, 1080030)  5.067753 0.4972365    4.764 -0.3037535 -0.4307643    4
    5 (2579700, 1079770)  5.116632 0.5792768    4.626 -0.4906319 -0.6446333    5
    6 (2579540, 1079640)  4.865667 0.6122453    6.522  1.6563325  2.1168243    6
    7 (2579860, 1079880)  5.139779 0.4655840    4.856 -0.2837789 -0.4158925    7
      outlier
    1 outlier                                                                   
    2 outlier                                                                   
    3  normal                                                                   
    4  normal                                                                   
    5  normal                                                                   
    6 outlier                                                                   
    7  normal 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table withe different columns as shown below Ref Number Service Numbers
I have a number of devices logging different data at different times and want
We have a number of different old school client-server C# WinForm client-side apps that
I have now written a number of different functions in Google Apps Script that
We have a number of servers running various different LAMP setups. One thing that
I have a Django form that uses a different number of fields based on
I have ten buttons that each correspond to a different number. I'm looking to
I have a product catalog. Each category consists of different number (in deep) of
We have a large number of programmers on different platforms all using CVS. We
I have a phone number field that can have lots of different characters such

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.