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

  • Home
  • SEARCH
  • 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 8943095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:41:24+00:00 2026-06-15T11:41:24+00:00

I think I’m just too tired to see the mistake. I wrote a function

  • 0

I think I’m just too tired to see the mistake. I wrote a function to get the maximal value for two data sets from a ‘for’ loop:

plot_zu <- function(x) {for (i in 1:x){
    z=data_raw[grep(a[i], data_raw$Gene.names),]
    b=data_raw_ace[grep(a[i], data_raw_ace$Gene.names),]
    p<-vector("numeric", length(1:length(a)))
    p[i]<-max(z$t_test_diff)
    return(p)} 
}

Imagine: a is a vector of names and the data set (data_raw(_ace)) is filtered by it. In the end, I would like to have all maxima values of column t_test_diff in a vector. After that I want to add the t_test_diff column values from data_raw_ace also.

So the problem is, that I get this:

[1] 1.210213 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
[8] 0.000000 0.000000

So there is a problem with brackets or something but I cannot see it ( first value fits). Sorry for no good example but i think it is understandable and an easy to solve question.

If need be, I can add another example.

Thanks a lot!!

gratefully,

Hendrik

  • 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-15T11:41:25+00:00Added an answer on June 15, 2026 at 11:41 am

    In the absence of data and even the call you make to this function, I’m going to offer an alternative based on what I think you are attempting. It appears you want to select only those rows of “data_raw” whose “Gene.names” column values are in the set defined by “a”. If so, that is just:

     z <- data_raw[ data_raw$Gene.names %in% a , ]  # no loop needed
    
     b <- data_raw_ace[ data_raw_ace$Gene.names %in% a , ] # again no loop needed
     # Next step is unclear
    

    If you want to use grep or grepl inside “[” then use sapply:

     z <- data_raw[ sapply(a, grep, x= data_raw$Gene.names), ]  # (still) no loop needed
     b <- data_raw_ace[ sapply(a, grep, x= data_raw_ace$Gene.names),  ]
    

    When you do this, what is it that is desired?

    p<-vector("numeric", length(1:length(a)))
    p[i]<-max(z$t_test_diff)
    

    If you want the maximum value for an identically named column in the two subset of data, then do this:

    p <- pmax( z$t_test_diff, b$t_test_diff )
    

    Based on you further comments above I (now) think maybe:

    p <- apply( cbind(z$t_test_diff), abs(b$t_test_diff), 1, function(x) x[which.max(abs(x))])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think that handlers in android are tools to get different objects that are
Think you are the proud owner of Facebook, then which data you want to
Think of the following code: static int Main() { byte[] data = File.ReadAllBytes(anyfile); SomeMethod(data);
I want to construct a data frame in an Rcpp function, but when I
Think about a table like this ID Value 100 1 100 3 101 1
Think this is my target key in registry: [HKEY_CURRENT_USER\System\Majid\0] GUID=hex:60,de,2a,56,51,b2,e0,11,80,01,44,45,53,54,00,00 as you can see
think user pressed two keys at same time . I want to be notified
think this should be an easy one... I want to get the currently selected
Think about doing this: import matplotlib.pyplot as plt plt.plot(x_A,y_A,'g--') plt.plot(x_B,y_B,'r-o') plt.show() How would you
Think I have an integer array like this: a[0]=60; a[1]=321; a[2]=5; now I want

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.