Skip to content

Subsetting dataframe by all factor levels

3 messages · Gabriel Gaona, Rich Shepard

#
On Fri, 14 Sep 2018, Justin H. wrote:

            
Justin,

   The rainfall data.frame structure:
'data.frame':   113569 obs. of  6 variables:
  $ name    : Factor w/ 58 levels "Blazed Alder",..: 20 20 20 20 20 20 20 20 ...
  $ easting : num  2370575 2370575 2370575 2370575 2370575 ...
  $ northing: num  199338 199338 199338 199338 199338 ...
  $ elev    : num  228 228 228 228 228 228 228 228 228 228 ...
  $ sampdate: Date, format: "2005-01-01" "2005-01-02" ...
  $ prcp    : num  0.59 0.08 0.1 0 0 0.02 0.05 0.1 0 0.02 ...

After splitting by name (only the first one shown):
str(rainfall_by_site)
List of 58
  $ Blazed Alder                 :'data.frame':      4900 obs. of  6 variables:
   ..$ name    : Factor w/ 58 levels "Blazed Alder",..: 1 1 1 1 1 1 1 1 1 1 ...
   ..$ easting : num [1:4900] 2393589 2393589 2393589 2393589 2393589 ...
   ..$ northing: num [1:4900] 196841 196841 196841 196841 196841 ...
   ..$ elev    : num [1:4900] 1112 1112 1112 1112 1112 ...
   ..$ sampdate: Date[1:4900], format: "2005-01-01" "2005-01-02" ...
   ..$ prcp    : num [1:4900] 0.2 0.2 0.4 0 0 0 0.1 0.1 0.1 0.2 ...

Adding a year column to the end:
     $ year    : num  0 0 0 0 0 0 0 0 0 0 ...

I've not separated the sampdate structure into years and months; I can and
that might make the difference. Will try to find time this weekend to do so.
Otherwise, it'll be next week.

Regards,

Rich
2 days later
#
An other option is the tydiverse way. I assume when you say " My goal is to
use the monthly mean rainfall at each of the 58 reporting stations..." you
mean you want for each year and station a average value of monthly prcp .
#
On Sun, 16 Sep 2018, Gabriel Gaona wrote:

            
Gabriel,

   Thank you very much I'm learning a lot from all the responses.

Best regards,

Rich