1

I am working with climate data in New Mexico and I am an R novice. I am trying to replace NA with means but there are 37 different sites in my df. I want the means of the column for which the DF$STATION.NAME (in column 1) is unique. I cant be using data from one location to find the mean of another... obviously. so really I should have a mean for each month, for each station.

My data is organized by station.name vertically in column 1 and readings for months jan-dec in columns following, including a total column at the end (right). readings or observations are for each station for each month, over several years (station name listed in new row for each new year.)

I need to replace the NAs with the sums of the CLDD for the given month within the given station.name, how do I do this?

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
user1680636
  • 51
  • 1
  • 6
  • Hi and welcome to StackOverflow. There are in fact many experienced R users here. One suggestion to improve this question is to provide a (small) reproducible example (see [this page](http://stackoverflow.com/q/5963269/1281189) for suggestions how). – BenBarnes Sep 19 '12 at 08:32
  • Also, to get you started on how to perform calculations over grouped rows of data, see [this question](http://stackoverflow.com/q/10748253/1281189). – BenBarnes Sep 19 '12 at 08:33

1 Answers1

0

Try asking that question on https://stats.stackexchange.com/ (as suggested by the tag), there are probably more R users there than on the general programming site. I also added the tag to your question.

There is nothing wrong with splitting your data into station-month subsets, filling the missing values there, then reassembling them into one big matrix!

See also: Replace mean or mode for missing values in R

Note that the common practice of filling missing values with means, medians or modes is popular, but may dilute your results since this will obviously reduce variance. Unless you have a strong physical argument why and how the missing values can be interpolated, it would be more elegant if you could find a way that can deal with missing values directly.

Community
  • 1
  • 1
Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194