0

I have used R's circular package as well as openair to plot wind roses. What I am not able to do is show the frequencies of the winds in the bin range (shown below) I would like to use. How does one determine the frequencies (percent and relative) using these packages? I would like to print these out or actually create an histogram using this. The bins are shown below

N, NNE, NE ENE, E, ESE, SE, SSE, S, SSW, SW, WSW, W, WNW, NW, NNW

require(openair)
require(circular)
df<- read.csv("Direction.csv", header = TRUE)
df1<-df[c(-1,-2,-3,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-20)]
dput(head(df2))
structure(list(X850mb = structure(c(355, 349, 350, 65, 36, 56, 
197, 282, 162, 219, 353, 32, 6, 14, 195, 45, 8, 182, 285, 285, 
260, 315, 341, 343, 321, 10, 49, 61, 49, 159, 170, 49, 64, 98, 
137, 178, 279, 173, 223, 221, 283, 246, 227, 231, 301, 212, 259, 
329, 293, 229, 205, 261, 354, 349, 254, 311, 47, 176, 195, 224, 
253, 293, 21, 34, 98, 225, 187, 204, 276, 280, 277, 233, 204, 
233, 218, 212, 279, 320, 334, 205, 288, 15, 325, 322, 356, 308, 
0, 343, 349, 10, 301, 340, 346, 281, 218, 305, 344, 304, 254, 
275, 246, 306, 271, 309, 191, 197, 296, 312, 224, 265, 336, 2, 
356, 336, 340, 349, 351, 11, 15, 306, 270, 249, 257, 271, 303, 
328, 358, 52, 241, 298, 309, 259, 285, 268, 313, 339, 359, 314, 
348, 309, 302, 322, 315, 285, 327, 327, 306, 29, 105, 111, 316, 
1, 25, 332, 352, 270, 275, 238, 308, 338, 343, 349, 339, 346, 
352, 24, 17, 5, 8, 9, 346, 318, 338, 22, 18, 337, 280, 274, 301, 
302, 286, 6, 43, 35, 6, 26, 356, 4, 356, 325, 336, 20, 345, 354, 
18, 54, 358, 313, 12, 327, 317, 329, 339, 274, 157, 143, 190, 
306, 327, 332, 359, 49, 14, 323, 328, 331, 1, 306, 339, 21, 33), circularp = structure(list(type = "angles", units = "degrees", 
    template = "geographics", modulo = "2pi", zero = 1.5707963267949, 
    rotation = "clock"), .Names = c("type", "units", "template", 
"modulo", "zero", "rotation")), class = c("circular", "integer"
))), .Names = "X850mb")
rose.diag(df2, bins = 16, main = '30yrs', col= 'darkgrey', prop = 2.0)
Gunnerfan
  • 123
  • 3
  • 10
  • 6
    If you want help, you're going to have to create a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output. Show what code you are using so far. Right now your list of cardinal directions has one of each value. I'm not clear what you want to do with that. – MrFlick Feb 27 '15 at 01:22
  • 1
    This is not a reproducible example. –  Feb 27 '15 at 01:47
  • But what command did you use, or try to use, to achieve your request? –  Feb 27 '15 at 02:50
  • There's no command in both packages to get the frequency out as a histogram or percent in bins. I'm a novice with R. The `rose.diag` only creates a rose diagram – Gunnerfan Feb 27 '15 at 02:53

1 Answers1

1

I suspect something like this is what you're after:

x <- cut(((as.vector(df2$X850)) +  360/(16*2) )%% 360,
    seq(0,360,360/16) ,
    c('N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'))
table(x)
Jthorpe
  • 9,756
  • 2
  • 49
  • 64
  • This is a step in the right direction. how do I tabulate them into a frequency table so I know how many occurrences of each there are? Essentially determine the frequency. – Gunnerfan Feb 27 '15 at 05:50
  • you want to use `table()` to tabulate the values. See edits. – Jthorpe Feb 27 '15 at 05:52
  • thanks for the help. Now when I want the `cumsum()` to perform the percentage statistics, i get this error `cumsum(table) Error in Math.factor(table) : ‘cumsum’ not meaningful for factors`. How would you determine this? I'm working on this right now myself to figure it out. Thanks! – Gunnerfan Feb 27 '15 at 06:15
  • try this: `cumsum(table(x))/length(x)` (Also, I realized there was a missing `(` above, which I fixed, but i assume you noticed/fixed it already.) Incidentally, `x` is a factor, which you can tell by calling `class(x)`, and `cumsum()` is only defined for numbers. Also, you must have a variable named 'table' otherwise the error message would have said `Error: cannot coerce type 'closure' to vector of type 'double'` since base::table is a function. R will let you overload variables and functions this way, but it's not good style (makes for some confusing debugging...) – Jthorpe Feb 27 '15 at 06:23
  • I saw that but I realized that when I first ran the code. May I ask as to your understanding why the `circular` and `openair` packages cannot tabulate the frequencies? – Gunnerfan Feb 27 '15 at 06:28
  • I have another question. What if I want to apply the `cut(((as.vector(df2$X850))' not to one column but to the entire columns minus date. I used `df2[i]` instead of `df2$X850` and got an error `Error in (function(x, i, exact) if (is.matrix(i)) as.matrix(x)[[i]] else .subset2(x, : object 'i' not found` How should I proceed or rectify this? – Gunnerfan Feb 27 '15 at 06:44