This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how to get name column having more number of gene occurrence

Hello All i have file for example like this:

s1 s2 s3 s4 s5 s6 
x   y   a   q   a  h
h   b   a   h   a  q
a   c   v   b   n  k
b   c   a

assuming a,b,c,d,e,f is my genes name

so as can be seen x is only present in one sample so i can say x is present in 16.6% population only present in s1

so i need some R code or some other way i can do?

gene occurence column

1 answer

Hi,

Input data

s1  s2  s3  s4  s5  s6
x   y   x   q   a   h
h   b   a   h   a   q
a   c   v   b   n   k
b   c   a   h   x   a

this may help

library("psych")

dat <- read.clipboard(header = T)
dat <- as.matrix(dat)

out_prcnt <- apply(dat,1, function(elem){

        fq <- table(elem)
        prcnt = fq/sum(fq) * 100
        return(prcnt)
})

Log in to answer this question.