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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:49:47+00:00 2026-05-27T00:49:47+00:00

Let’s say I have a data frame with numerical values like this AA01.AVG_Beta AA02.AVG_Beta

  • 0

Let’s say I have a data frame with numerical values like this

AA01.AVG_Beta AA02.AVG_Beta AA03.AVG_Beta AA04.AVG_Beta AA05.AVG_Beta
1     0.15851770    0.44264830    0.46662180    0.79579230   0.555430100
2     0.87148450    0.93462340    0.92591830    0.93812860   0.942683400
3     0.60907060    0.92463760    0.62698660    0.86852790   0.457659300
4     0.10728340    0.07848221    0.06340047    0.08589865   0.118239800
5     0.72353630    0.91198210    0.87339600    0.88050440   0.902925300
6     0.52616050    0.57114700    0.29431990    0.56032260   0.530103800
7     0.50321330    0.78129660    0.26986880    0.77825860   0.924097500
8     0.47808630    0.11267250    0.30519660    0.36128510   0.741012600
9     0.17698960    0.11461960    0.57776080    0.37801670   0.465766500
10    0.01268375    0.01370702    0.01194124    0.01227029   0.009222724

I want to change all numerical values to letter in each row using these conditions

Avg beta 0-0.2 change to AA,
Avg beta 0.4-0.6 change to AB,
Avg beta 0.8-1 change to BB

So I wrote something like that

apply(table, 2, function(x) ifelse (x>0 & x< 0.2, "AA",ifelse(x>0.4 & x<0.6,"AB",
+ "BB"))  )

But I get this

AA01.AVG_Beta AA02.AVG_Beta AA03.AVG_Beta AA04.AVG_Beta AA05.AVG_Beta
[1,] "AA"          NA            NA            NA            NA           
[2,] "BB"          NA            NA            NA            NA           
[3,] "BB"          NA            NA            NA            NA           
[4,] "AA"          NA            NA            NA            NA           
[5,] "BB"          NA            NA            NA            NA           
[6,] "AB"          NA            NA            NA            NA           
[7,] "AB"          NA            NA            NA            NA           
[8,] "AB"          NA            NA            NA            NA           
[9,] "AA"          NA            NA            NA            NA           
[10,] "AA"          NA            NA            NA            NA 

only the first column
maybe I am missing something related with for loops?

Thanks in advance

  • 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-27T00:49:48+00:00Added an answer on May 27, 2026 at 12:49 am

    Use sapply instead of apply:

    Recreate your data:

    dat <- read.table(text="
    AA01.AVG_Beta AA02.AVG_Beta AA03.AVG_Beta AA04.AVG_Beta AA05.AVG_Beta
    1     0.15851770    0.44264830    0.46662180    0.79579230   0.555430100
    2     0.87148450    0.93462340    0.92591830    0.93812860   0.942683400
    3     0.60907060    0.92463760    0.62698660    0.86852790   0.457659300
    4     0.10728340    0.07848221    0.06340047    0.08589865   0.118239800
    5     0.72353630    0.91198210    0.87339600    0.88050440   0.902925300
    6     0.52616050    0.57114700    0.29431990    0.56032260   0.530103800
    7     0.50321330    0.78129660    0.26986880    0.77825860   0.924097500
    8     0.47808630    0.11267250    0.30519660    0.36128510   0.741012600
    9     0.17698960    0.11461960    0.57776080    0.37801670   0.465766500
    10    0.01268375    0.01370702    0.01194124    0.01227029   0.009222724
    ")
    

    Use sapply:

    sapply(dat, function(x) 
          ifelse (x>0 & x< 0.2, "AA",ifelse(x>0.4 & x<0.6,"AB", "BB"))
    )
    
          AA01.AVG_Beta AA02.AVG_Beta AA03.AVG_Beta AA04.AVG_Beta AA05.AVG_Beta
     [1,] "AA"          "AB"          "AB"          "BB"          "AB"         
     [2,] "BB"          "BB"          "BB"          "BB"          "BB"         
     [3,] "BB"          "BB"          "BB"          "BB"          "AB"         
     [4,] "AA"          "AA"          "AA"          "AA"          "AA"         
     [5,] "BB"          "BB"          "BB"          "BB"          "BB"         
     [6,] "AB"          "AB"          "BB"          "AB"          "AB"         
     [7,] "AB"          "BB"          "BB"          "BB"          "BB"         
     [8,] "AB"          "AA"          "BB"          "BB"          "BB"         
     [9,] "AA"          "AA"          "AB"          "BB"          "AB"         
    [10,] "AA"          "AA"          "AA"          "AA"          "AA"       
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have table with column 'URL' whrere I store urls like this
Let's say that I have a set of relations that looks like this: relations
Let's say that I have classes like this: public class Parent { public int
Let's say I'm building a data access layer for an application. Typically I have
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I can call a method like this: core::get() . What is the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let's say I have this interface: // .h @interface DataObject : NSObject { NSString*

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.