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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:38:19+00:00 2026-05-25T17:38:19+00:00

I have 507 tables with (pattern = human). Inside each table there are a

  • 0

I have 507 tables with (pattern = “human”).
Inside each table there are a number of columns that I want to compare via Student’s t-test. Before I learned ‘functions’, I was initializing 16 columns in my data.frame and copying a lot of code for 16 comparisons. 🙁 But I want to simplfy the code by using functions.

Q: Do I need a counter of some sort or to use ‘cbind’? or what??
Any suggestions?

files_to_test <- list.files(pattern="human")  
num_files <- length(files_to_test)  

## Function: Calculate t-test P-values ##
g<-function(compareA,compareB) {
   for (i in 1:num_files){
      temp <- read.table(files_to_test[i], header=TRUE, sep="\t")
      ## Obtain Columns To Compare ##
      colA <- temp[compareA]
      colB <- temp[compareB]
      ttr <- t.test(colA, colB, var.equal=TRUE)
      tt_pvalues[i,1] <- ttr$p.value
      }
tag <- paste(compareA, compareB, sep="_Vs_")
tt_titles <- data.frame(tag,tt_titles) # Here is my problem.  
ALL_pvalues <- data.frame(tt_pvalues, ALL_pvalues) # Here is my problem.  
}

## Comparison 1
compareA <-"log_b" 
compareB <-"log_b_rich"
g(compareA,compareB)

## Comparison 2
compareA <-"fc_Etoh_CDT_tot_poly"
compareB <-"log_b_rich"
g(compareA,compareB)

My expected output should be:

source.file.name, tag[i], tag[j], ...  
files_to_test[1], #, #, ...  
files_to_test[2], #, #, ...  

What I am trying to do is append or fold my newly tabulated ttest data with the earlier ttest data, either by cbind or data.frame. I’m not sure.

  • 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-05-25T17:38:20+00:00Added an answer on May 25, 2026 at 5:38 pm

    I think you need to move the tagging operation inside the loop:

    # Pre-allocate tag[i] outside the loop
    tag <- vector("character", length=num.files)
    
    g<-function(compareA,compareB) {
       for (i in 1:num_files){
          temp <- read.table(files_to_test[i], header=TRUE, sep="\t")
          ## Obtain Columns To Compare ##
          colA <- temp[compareA]
          colB <- temp[compareB]
          ttr <- t.test(colA, colB, var.equal=TRUE)
          tt_pvalues[i,1] <- ttr$p.value
       tag[i] <- paste(compareA, i, "Vs" compareB, i sep="_")
          }
    
    tt_titles <- data.frame(tag, tt_titles) # Here is my problem.  
    ALL_pvalues <- data.frame(tt_pvalues, ALL_pvalues) # Here is my problem.  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a LinqtoSql query that I now want to precompile. var unorderedc = from
Have some data in a sybase image type column that I want to use
I have a couple of tables (products and suppliers) and want to find out
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you determined a maximum number of characters allowed in FCKEditor ? I seem
Have you refactored from an ActiveRecord to a DataMapper pattern? What conditions prompted the
Possible Duplicate: Format numbers in javascript I have a string represents a number: 3507654
Have created simple Ajax enabled contact forms before that have around 12 fields -
I have A TabActivity that hosts other activities, on the tabactivity I have a
I have a class SomeTaskManager with an abstract method runATask . I want to

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.