Bash: awk: Calculate average of first 10 rows in column?
1
0
Entering edit mode
3.3 years ago

Hi all,

I'm working with video data for drug phenotypes on some mutant cell lines. Output is thousands of columns of pixel intensity data vs time (each row being a new frame of the video). I want to normalise the data in each column against an average of the first 10 data points from that column. I'm no geek btw, so go easy!!

Put simply:

  1. I need to take an average of the first 10 rows of the column (and store that average in a new column or document) But I can't work out how to ONLY do that calculation on the first 10 rows rather than on the whole column (147 rows in total)

  2. I need to divide every data point in the column by that average (I can probably work this one out myself, once I've got the answer to question 1!)

Here's an example of the data

https://drive.google.com/open?id=16ZhC-OjNTIpXkWek02BJx2qOgh1Xv889TDTbOdprDYk

Thanks very much!! Ewan

awk .csv bash • 2.9k views
ADD COMMENT
0
Entering edit mode

If you are using Linux you should read head -h.

head -n 10 your_input

ADD REPLY
1
Entering edit mode
3.3 years ago
 awk '(NR<=10) {array[NR]=int($0);next;} (NR==11) {T=0;for(i=1;i<11;i++) T+=array[i]; T=T/10.0; for(i=1;i<11;i++) print array[i]/T;} { print int($0)/T;}' input.txt
ADD COMMENT

Login before adding your answer.

Traffic: 1938 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