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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:44:47+00:00 2026-05-26T11:44:47+00:00

is it possible to do the following: loc1 <- c(Aa, Aa, aa, Aa) loc2

  • 0

is it possible to do the following:

loc1 <- c("Aa", "Aa", "aa", "Aa")
loc2 <- c("aa", "aa", "aa", "AA")
loc3 <- c("aa", "Aa", "aa", "aa")
gen <- data.frame(loc1, loc2, loc3)

loc1g <- c(0.01, 0.5, 1, 0.75)
loc2g <- c(0.2, 0.1, 0.2, 0.6)
loc3g <- c(0.8, 0.8, 0.55, 1)
pval <- data.frame(loc1g, loc2g, loc3g)

I want to print to a file to gen dataframe such way that is conditionally formatted by the pval dataframe. Means than (row1, col1) of gen color depends upon pvale (row1, col1). The following are color coding:

0 to 0.3   is "red" text color 
0.31 to 0.7 is "yellow"
> 0.7  is "red" 

gen[1,1] will be “Aa” printed in red text color and so on….

appreciated your help.

EDITS:

I am more interested in printing not plotting in graph. If I can save output as MS excel and open in MSEXCEL it would be great. I can also be other types of text editors format that can read color coded text. As my orginal data matrix should be of a dimension of 1000 x 1000 or even more. I would like to quicky know unlying p-value for each gen categories.

  • 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-26T11:44:47+00:00Added an answer on May 26, 2026 at 11:44 am

    Giving a POC-like answer which is using an ugly loop and not the most beatiful design:

    Loading eg. the xlxs package to be able to write to Excel 2007 format:

    library(xlsx)
    

    Let us create a workbook and a sheet (see the manual!):

    wb <- createWorkbook()
    sheet <- createSheet(wb, "demo")
    

    Define some styles to use in the spreadsheet:

    red <- createCellStyle(wb, fillBackgroundColor="tomato", fillForegroundColor="yellow", fillPattern="BIG_SPOTS")
    yellow <- createCellStyle(wb, fillBackgroundColor="yellow", fillForegroundColor="tomato", fillPattern="BRICKS1")
    

    And the ugly loop which is pasting each cell to the spreadsheet with appropriate format:

    for (i in 1:nrow(pval)) {
        rows <- createRow(sheet, rowIndex=i)
        for (j in 1:ncol(pval)) {
            cell.1 <- createCell(rows, colIndex=j)[[1,1]]
            setCellValue(cell.1, gen[i,j])
            if ((pval[i,j] < 0.3) | (pval[i,j] > 0.7)) {
                setCellStyle(cell.1, red)
            } else {
                setCellStyle(cell.1, yellow)
            }
        }
    }
    

    Saving the Excel file:

    saveWorkbook(wb, '/tmp/demo.xls')
    

    Result: demo.xls


    Alternative solution with package ascii:

    ascii.data.frame() can export data frames to a bunch of formats with the ability of adding some formatting. E.g. exporting to pandoc, first define the styles of each cells to an array with the same dimensions as pval:

    style <- matrix('d', dim(pval)[1], dim(pval)[2])
    style[pval < 0.3 | pval > 0.7] <- 's'
    

    Set the desired output:

    options(asciiType = "pandoc")
    

    And export the data frame:

    > ascii(gen, style=cbind('h', style))
    
        **loc1**   **loc2**   **loc3**  
    --- ---------- ---------- ----------
    1   Aa         **aa**     **aa**    
    2   **Aa**     **aa**     Aa        
    3   **aa**     aa         **aa**    
    4   **Aa**     **AA**     **aa**    
    --- ---------- ---------- ----------
    

    With ascii::Report you could easily convert it it pdf, odt or html. Just try it 🙂 Small demo with HTML output: result

    r <- Report$new()
    r$add(section("Demo"))
    r$add(ascii(gen, style=cbind('h', style)))
    options(asciiType = "pandoc")
    r$backend <- "pandoc"
    r$format <- "html"
    r$create()
    

    And odt output: result

    r$format <- "odt"
    r$create()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How is the following possible: void contains(LinkedHashSet data, Object arg) { System.out.println(data.getClass()); // java.util.LinkedHashSet
Is the following possible in SQL Server 2000? CREATE FUNCTION getItemType (@code varchar(18)) RETURNS
Is something like the following possible in PHP? $blah = 'foo1'; class foo2 extends
For instance, is the following possible: #define definer(x) #define #x?
any idea how if the following is possible in PHP as a single line
I was wondering if the following is possible. Create a class that accepts an
I'd like to know whether the following is possible with C# properties. I have
Possible Duplicate: Singleton: How should it be used Following on from Ewan Makepeace 's
Is the following at all possible in c#? I have the following but the
What could be the possible causes for the following exception? System.PlatformNotSupportedException: 'ResourcePool' is not

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.