Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Mean of every two columns for large dataset

As shown below I have a large dataset with 12 hourly temperatures organised in columns. I wish to take the daily mean, i.e. average two columns at a time until the end of the dataset. Could somebody point me in the direction of an easy solution? I know this is probably very straightforward but I can’t find any existing solution.

01.01.2000 00:00     01.01.2000 12:00     02.01.2000 00:00     02.01.2000 12.00
3.5                  8.9                  3.8                  9.1

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Get the indexes of odd and even columns and calculate an average:

odds = seq(1, ncol(your_data), by = 2)
evens = odds + 1
result = (your_data[odds] + your_data[evens]) / 2
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading