how to reorder lines in afile based on a list of gene IDS?
0
0
Entering edit mode
5.6 years ago
majeedaasim ▴ 60

I have two files;

File one:

ID  SCORE   PVALUE
A   1   0.1
B   2   0.2
C   3   0.3
D   4   0.4

FIle 2:

ID
C
B
A

Now I want to reorder my file 1, in the sequence as present in file 2.

THanks

reorder • 1.3k views
ADD COMMENT
1
Entering edit mode

And what have you tried to solve this?

ADD REPLY
1
Entering edit mode

In R, just set the column as factor with your levels for the dataframe.

For others, storing the levels in a hashmap with incremental numbers as values, then you can sort the rows using corresponding hashmap value.

Want save time? csvtk sort supports sorting by user defined levels.

ADD REPLY
0
Entering edit mode

Do you want a solution in Perl, Python or R?

ADD REPLY
0
Entering edit mode

I want solution in R

ADD REPLY
0
Entering edit mode

why not trying googling using keywords "r dataframe reorder factor"?

ADD REPLY

Login before adding your answer.

Traffic: 2470 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6