This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to keep the gene id with highly FPKM.

I have a text file contains three columns; the first coulmn is the Ensemble gene id, the second column is gene name, and the third column is FPKM. I am looking for R function to keep the Ensemble gene id that highly expressed (i.e has highest FPKM) only in this file.

Example: from the data below, I want only to keep ENSMUST00000062483 Gli2 0.157666 which has the highest FPKM

ex

r

That's a very basic R question. I would suggest you to follow tutorial on basic R programming, this will make everything less painful in the long run. Specifically, you are looking for the row (slicing) for which the FPKM value is equal to the maximum value of all FPKM values.

2 answers

newdata <- yourdataframe[order(-yourdataframe$FPKM),]

The "-" before yourdataframe$FPKM indicates "descending" without it will be "ascending"

That's worked, but it gave me all highest FPKMs. What I need to keep the highest one only (i.e the highest value among all higher FPKM values)

    highest <- newdata [1,]

I hope this helps

Yourdata <- read.table("yourfile.txt", sep="\t", row.names=1, header=FALSE)
HighlyExpressedID <- rownames(Yourdata[order(Yourdata[,2],decreasing=TRUE),])[1:n]

Just replace "n" with the number of gene id that you want to keep.

I hope this helps

Log in to answer this question.