[R-sig-Geo] Subsetting dataframe by all factor levels

Rich Shepard r@hep@rd @ending from @ppl-eco@y@@com
Sat Sep 15 00:54:15 CEST 2018


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

> I'm not sure how it handles your date format. It's probably grouping
> things weirdly. If you can split out that column into two columns, one for
> year and one for month. I'd have to tinker with it later as I can't think
> of code off the top of my head. It should play nicer then.

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



More information about the R-sig-Geo mailing list