I would like to average the columns in a data frame in R, which contains integer values, and sometimes NA.
The information frame is called CD6 (Climate Division 6), which is initialized with NA values ββto store the average values ββfor all data related to Climate 6. The rows represent dates, and the columns represent hours from 0 to 23. The data screen looks like this: this:
> CD6 Date H0 H1 H2 H3 H4 H5 H6 H7 H8 H9 H10 ... H23 1948-07-01 NA NA NA NA NA NA NA NA NA NA NA ... NA 1948-07-02 NA NA NA NA NA NA NA NA NA NA NA ... NA 1948-07-03 NA NA NA NA NA NA NA NA NA NA NA ... NA
An information frame called CA has true values ββfor all climate divisions from 1 to 7. The data frame looks something like this:
> CA Climate_Division Date H0 H1 H2 H3 H4 H5 H6 H7 H8 H9 H10 ... H23 6 1948-07-01 NA NA NA NA NA NA NA NA NA NA NA ... NA 5 1948-07-01 0 1 1 3 0 0 0 0 0 0 0 ... 2 6 1948-07-01 0 1 1 3 0 0 0 0 0 0 0 ... 2 6 1948-07-01 1 0 0 5 7 0 1 1 1 0 0 ... 0 6 1948-07-02 0 2 1 2 1 1 NA 0 1 0 1 ... 2 6 1948-07-03 NA NA NA NA NA NA NA NA NA NA NA ... NA
I have a coded loop that will go through the data center row-by-row CA and display the correct data frame for climate separation (in this example, CD6 for climate separation 6). The problem is that I do not know how many lines there are for each climate division, so that on average to accept it.
If you look only at CD6, I would like to get the average value for each date at a certain hour, which NA ignores if true values ββare present, and the final answer is an integer (value ceiling). If all the clocks in different climate departments are NA, I would like to keep it so that it contrasts 0. The end result should look like this for CD6
> CD6 Date H0 H1 H2 H3 H4 H5 H6 H7 H8 H9 H10 ... H23 1948-07-01 1 1 1 4 4 0 1 1 1 0 0 ... 1 1948-07-02 0 2 1 2 1 1 NA 0 1 0 1 ... 2 1948-07-03 NA NA NA NA NA NA NA NA NA NA NA ... NA
I do not know exactly how to do this, coding it and possessing its skills. Therefore, any suggestions will be useful and grateful for your time.