1

How can I print the row name if the maximum value is 2 times higher than median value of the rest of the values.

input

name s1 s2 s3 g1 20.17 0.21 0.57 g2 0.19 0.19 94.0 g3 0.15 0.21 0.26 g4 0.09 0.19 0.16 g5 0.019 0.19 0 g7 2.28 0 0 

output

g1 s1 20.17 g2 s3 94.0 g7 s1 2.28 
2
  • how does 0.28 come in 2 times higher than 0 ? Commented Jun 22, 2017 at 14:27
  • oops sorry. corrected. Commented Jun 22, 2017 at 14:30

1 Answer 1

2

awk solution:

awk 'NR>1{ k=$3*2; f=""; if($2>k) f="s1" OFS $2; else if($4>k) f="s3" OFS $4; if (f!="") print $1,f }' OFS='\t' file 

The output:

g1 s1 20.17 g2 s3 94.0 g7 s1 2.28 
4
  • Is it possible to apply this code to a big matrix that has many columns. thanks Commented Jun 22, 2017 at 14:40
  • @user1883491, hi, it depends on how big is that matrix and what would be the median value in it Commented Jun 22, 2017 at 14:41
  • I have 10k columns and 1000 rows. Commented Jun 22, 2017 at 14:43
  • @user1883491, quite big. I would initiate new question in your place. In that case you need to add an additional operation such as "searching the median field number beforehand" Commented Jun 22, 2017 at 14:58

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.