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

(R) Data Frame Manipulation – Huge Dataset

I got a huge dataset consisting of meteorological data collected every hour from 01.01.2003 until 31.12.2023 (Picture from part of the dataset). This dataset has 24 rows for each day and 1 row for each hour of these 20 years.

I want to have another data frame in my script that contains columns deriving from the original date frame. These columns would be "Date" – one row per day, "AvgAirTemp" – average air temperature that day, "MaxAirTemp" – maximum air temperature that day, "MinAirTemp" – "minimum air temperature that day.

Creating the new data frame isn’t the problem, I have it already. But I couldn’t find how to calculate the average of the values in 24 rows and transpose it to the right row/column in the new data frame. The same for the max and min values. I was trying to find a way to use mutate for this, but no success.

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

I appreciate your assistance.

>Solution :

Since you mention mutate, I am assuming you are using dplyr. If not, you can follow the same logic with aggregate.

data |> group_by(Data) |> mutate(Mean_Temp = mean(DryAirTemp), Min_Temp = min(DryAirTemp))  - > dailydata

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