Question: how to reorder lines in afile based on a list of gene IDS?
0
gravatar for majeedaasim
4 weeks ago by
majeedaasim20
United States
majeedaasim20 wrote:

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 • 145 views
ADD COMMENTlink written 4 weeks ago by majeedaasim20
1

And what have you tried to solve this?

ADD REPLYlink written 4 weeks ago by WouterDeCoster32k
1

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 REPLYlink written 4 weeks ago by shenwei3564.1k

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

ADD REPLYlink written 4 weeks ago by h.mon20k

I want solution in R

ADD REPLYlink written 4 weeks ago by majeedaasim20

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

ADD REPLYlink written 4 weeks ago by shenwei3564.1k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1556 users visited in the last hour