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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:08:27+00:00 2026-05-24T14:08:27+00:00

I am not sure the title is clear enough. I have a dataframe (see

  • 0

I am not sure the title is clear enough.
I have a dataframe (see below) which contains values across 5 columns. What I would like to do is to "split" this dataframe into three classes where the rows can be assigned into a "High", "Medium", "Low" state.

What I mean is :

High: the values are "high" in at least 3 columns

Medium: the values are "medium" in a least 3 columns

Low: the values are "Low"(or NA) in a least 3 columns

I guess it involve two things, defining the value cutoff for the 3 groups, then assinging rows into High, Medium and Low category… but thats a guess

The data file is available here

tmp = read.table("tmp2.txt", header=TRUE)
head(tmp)
           Geneid     Hsap      Mmul      Mmus      Rnor     Cfam
1 ENSG00000197711 365823.5 243429.20 44337.267 156874.50 128015.0
2 ENSG00000198712 198613.0        NA 47767.767 200176.50 210559.8
3 ENSG00000198899 189421.5        NA        NA 283425.50 367112.8
4 ENSG00000198804 182559.5        NA 87301.900 277861.00 324438.0
5 ENSG00000198840 142424.5        NA  8400.457  45844.80 115027.9
6 ENSG00000171564 119147.9  93564.66  6675.290  45938.85  45140.2

Any advices strongly appreciated, as I don’t have the slightest idea on how to tackle this !

Thanks,


This is the answer below :

I have now replaced the file by a more realistic one (more rows)

tbl <- read.csv("http://db.tt/L2ehGh8", header=FALSE)
colnames(tbl) <- c("Geneid","Hsap","Mmul","Mmus","Rnor","Cfam")

Using cut() :
I have lots of 0s, and the values are quiet stretched, so by using log, or here asinh, you get rid of this.

tbl.data <- apply(asinh(tbl.data),2,
                  function(x) as.numeric(as.factor(cut(x,4)))  )
head(tbl.data)
     Hsap Mmul Mmus Rnor Cfam
[1,]    2    2    1    1    2
[2,]    2    2    2    2    2
[3,]    1    1    1    1    1
[4,]    1    1    1    1    1
[5,]    2    3    2    2    3
[6,]    2    2    2    2    2

Another way is to use Quantiles, which as been shown to me.

quantile(tbl.data[,1],0.25)
quantile(tbl.data[,1],0.5)
quantile(tbl.data[,1],0.75)

tbl.data2 <- apply(tbl.data,2,
                   function(x) as.numeric(as.factor(cut(x,c(-1,
                       quantile(x, 0.25)+0.0001,
                       quantile(x,0.5),
                       quantile(x,0.75), max(x))))))
head(tbl.data2)
     Hsap Mmul Mmus Rnor Cfam
[1,]    3    3    3    2    3
[2,]    2    3    4    3    3
[3,]    2    1    1    1    2
[4,]    1    2    1    1    1
[5,]    4    4    4    4    4
[6,]    3    4    4    3    4
  • 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-24T14:08:28+00:00Added an answer on May 24, 2026 at 2:08 pm

    Assuming you want NAs to be handled by not counting them rather than tossing the whole row:

    tbl <- read.table("http://db.tt/Eb6qM4h",header=TRUE)
    tbl.data <- subset(tbl,select=-Geneid)
    tbl.data <- apply(tbl.data,2,function(x) as.numeric(as.factor(cut(x,3)))  )
    
    
    countLevels <- function(tbl.data,lvl) {
      apply(tbl.data,1,function(x) sum( x[!is.na(x)] == lvl ) )
    }
    
    tbl.final <- tbl.new <- subset(tbl,select=Geneid)
    for(lvl in seq(3) ) {
      tbl.new[,paste('Level',lvl)] <- (countLevels(tbl.data,lvl) > 3) * lvl
    }
    
    tbl.final$Levels <- rowSums(subset(tbl.new,select=-Geneid))
    

    Which returns the data.frame as follows:

    > head(tbl.final,20)
                Geneid Levels
    1  ENSG00000197711      0
    2  ENSG00000198712      0
    3  ENSG00000198899      0
    4  ENSG00000198804      0
    5  ENSG00000198840      0
    6  ENSG00000171564      1
    7  ENSG00000171557      1
    8  ENSG00000198727      1
    9  ENSG00000163631      0
    10 ENSG00000198888      1
    11 ENSG00000198695      1
    12 ENSG00000198763      1
    13 ENSG00000198786      1
    14 ENSG00000158874      0
    15 ENSG00000138207      1
    16 ENSG00000109072      1
    17 ENSG00000130203      3
    18 ENSG00000106927      1
    19 ENSG00000110169      1
    20 ENSG00000104760      1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am not sure if my title is clear enough. I essentially have
Ok, I'm not sure that my title was clear enough, but I will try
I'm not sure if the title is very clear, but basically what I have
The title may not seem very clear - was not sure how to explain
I am not sure how clear my question is by the title, but I
I am not sure my title is correct or not since I have no
I am not sure if the title is accurate. I have several classes like
Sorry if my title is not clear, I'm not sure how to word this.
Not sure if the title is very clear but I don't know the exact
Not sure if I'm being too clear with the title. Sorry, it's late and

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.