0

First time posting a question here. Useless times this forum helped, but now, I fell my R skills are not strong enough to do the job.

My problem is: I have a Spatial Data frame with multiples attributes, such as Grid_code (pixels values, integer), Sub_Population(Character) and Origin_year (integer). I need to find the break values, in this case, 3 breaks values to place 1/4 of the pixels in each class - that will be 4 classes. Also, this breaks will vary regarding the Sub_population and Origin_year unique combination.

 SubPop    Origin   grid_code
 AL        2008   4.730380
 AL        2008   5.552315
 AL        2008   5.968850
 AL        2008   5.128384
 AL        2009   6.927450
 AL        2009   7.135734
 ALCentral    2008   7.381087
 ALCentral    2008   6.232927
 ALCentral    2009   6.431800
 ALCentral    2009   6.690246
 ALCentral    2009   6.794144

That said, the breaks that will allocate the pixels into 4 different classes (1/4 of pixels in each class) will be a unique single set for each combination of Sub_population and Origin_Year.

What I'm thinking to do:

For each unique combination of Sub_population and Origin_year I'll create a df.

> cstands_spdf_split <- cstands_select_df[ which(
> cstands_select_df$SubPop == "AL" | cstands_select_df$Origin
> ==2008) , ]

Now I need to know for to define the breaks for this unique combination. I was thinking in using the split function with quantiles, but I don't know how this can be done...

Within the time and leaning I'll update this script to be used to run like a function.

Any feedback is appreciate.

Huub
  • 1
  • 1
  • 1
    Welcome to SO. Please read [How to make a great reproducible example in R?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). This way we can help you to resolve your problem. – M-- Jun 21 '17 at 20:42
  • I know how to create breaks along a single variable. I don't know how you intend to do that through more than one variable. Perhaps you should create the `split` variable inside your main data.frame, and proceed from there? – Rodrigo Jun 21 '17 at 20:49
  • Thanks Masoud. I'll try to improve my question based on your link. – Huub Jun 21 '17 at 20:50
  • Rodrigo, I need to find breaks or values that will place 1/4 of the grid_code into 4 different classes for each of the combination of the SubPop and Origin. At the end, I'll have a list with the 3 Break Values that will separate the grid_code into into four classes. Does it make sense now? It's complicated to explain, and if you didn't get the idea I can try to improve my question again. – Huub Jun 21 '17 at 21:19
  • What should your output look like? – CPak Jun 21 '17 at 22:17
  • @ChiPak the format of the output would be a list object with 3 "break values" ( the values that will place 1/4 of the pixels in 4 different classes). This list will contain a set of the 3 break values depending of the unique combination of SubPop and Origin. That said, for the dataframe I've posted (imagine this dataset with 33000 rows and more SubPop and Origin), I'll have a list for AL & 2008, AL & 2009, ALCentral & 2008 and ALCentral & 2009 = an Object with 4 lists and each one with 3 break values. – Huub Jun 22 '17 at 15:02

0 Answers0