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 9003561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:43:39+00:00 2026-06-16T00:43:39+00:00

I have many variables having many observations. I have one standard variable. Now, I

  • 0

I have many variables having many observations. I have one standard variable. Now, I want to calculate the difference between the standard and observed variables only when the observation is bigger than the standard and summing up all the differences as a separate variables. In addition, the names of the variables that are bigger than the standard in a separate column.

Names   Standard    Das Dss Tri Tet
Aa  32  42  21  45  34
Ab  23  25  43  43  32
Ac  43  34  23  32  23
Ad  23  24  33  12  23
Ae  14  24  12  20  24
Af  43  42  13  12  43
Ag  12  13  22  13  22
Ah  32  32  42  42  23

OUTPUT:

Names   Standard    Das Dss Tri Tet Difference  No_Difference   Names_Difference
Aa  32  42  21  45  34  15  3   Das, Tri, Tet
Ab  23  25  43  43  32  52  4   Das,Dss,Tri,Tet
Ac  43  34  23  32  23  0   0   NA
Ad  23  24  33  12  23  10  2   Das,Dss
Ae  14  24  12  20  24  26  4   Das,Tri,Tet
Af  43  42  13  12  43  0   0   NA
Ag  12  13  22  13  22  22  4   Das,Dss,Tri,Tet
Ah  32  32  42  42  23  20  2   Dss,Tri
  • 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-16T00:43:40+00:00Added an answer on June 16, 2026 at 12:43 am

    Let’s say your data from above is stored in the object df. Then this should work

    df2 <- do.call(rbind, apply(df[, -1], 1, function(z) {
            ind <- z[2:5] > z[1]
            return(cbind.data.frame(
                            Difference = sum(z[2:5][ind] - z[1]), 
                            No_Difference = sum(ind), 
                            Names_Difference = paste(colnames(df[3:6])[ind], 
                                    collapse = ", ")
                    ))
        }))
    
    df <- cbind(df, df2)
    df
    
      Names Standard Das Dss Tri Tet Difference No_Difference   Names_Difference
    1    Aa       32  42  21  45  34         25             3      Das, Tri, Tet
    2    Ab       23  25  43  43  32         51             4 Das, Dss, Tri, Tet
    3    Ac       43  34  23  32  23          0             0                   
    4    Ad       23  24  33  12  23         11             2           Das, Dss
    5    Ae       14  24  12  20  24         26             3      Das, Tri, Tet
    6    Af       43  42  13  12  43          0             0                   
    7    Ag       12  13  22  13  22         22             4 Das, Dss, Tri, Tet
    8    Ah       32  32  42  42  23         20             2           Dss, Tri
    

    Altough this is not really elegant and it’s not very robust to use integers to index columns, in case the ordering of your variables changes at some point

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to share my session variables in PHP using many subdomains. I have
so i have many controllers and many views. i want my variable @random_quote to
I have a js variable with many functions, and I want to create in
I have objects with many variables that I declare and explain in the comments.
I have many js methods that uses global variables like: function DoSomething() { var
I have a VBA code where I compute the values of many variables (For
I have a ASP Page and it has so many date variables. myvariable =
I have a variable that I'm using many times in a class and as
i am having many activities like settings,game,home etc.i want to accept some values from
I'm having trouble with the webparts variables... I came from standard ASP language, so,

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.