0

I've sampled raster ASPECT data which ranges from 0-360 and now I want to group these data into directions (North, South, East, East, etc).

I found the cut function and wanted to try using that, but something seems to not be working. For my breaks, I have 10 ranges, but I keep getting the error that the length of my breaks and labels differs. It says that the length of my breaks is 20 and I'm not sure why. Any advice?

ForestType$Aspect<-cut(ForestType$Aspect,
                           breaks= c(c(-2,-1), c(0,22.5),c(22.51,67.5), c(67.51,112.5),c(112.51,157.5), c(157.51,202.5), c(202.51,247.5), c(247.51,292.5),c(292.51,337.5),c(337.51,360)), 
                           labels= c("Flat", "North", "Northeast", "East","Southeast", "South", "Southwest", "West","Northwest", "North"), right=F)
fedorqui
  • 275,237
  • 103
  • 548
  • 598

1 Answers1

1

Breaks should be continuous. In your case cut consider gaps between your vectors (e. g. -1;0) as breaks for which labels are needed. Generally breaks looks like this: c(-2,-1, 0,22.5, 67.5,112.5,157.5,202.5,247.5,292.5,337.5,360)

Gregory Demin
  • 4,596
  • 2
  • 20
  • 20
  • I'm still confused. How do I cut? I tried putting the semi-colons in between vectors but I get an error. If i just put in full line of values, there is a mismatch with my labels again. Any ideas? – Andrew Budsock Mar 13 '17 at 18:05
  • @AndrewBudsock `cut` make continious intervals. For example, `cut(runif(10), c(0.2, .25, .5, 1))` gives variable with three intervals - (0.2,0.25], (0.25,0.5], (0.5,1]. Values which are outside these intervals become NA. – Gregory Demin Mar 13 '17 at 20:07