Dear R users,
I want to group numerical values in classes with different size and count
the values for each classes.
My data is in this forma:
d 15 12,5 30,4 20,5 80,4 100,5 8,2 40,5 33 21 11
And I want the group them in classes with 4 (5,....etc) cm size like this:
class d 16 16 32 24 84 104 12 44 36 24 12
and final to count values for each class:
class d n 12 2 16 2 24 2 32 1 36 1 44 1
84 1 104 1 Total 11
Thank you!
--
---
Catalin-Constantin ROIBU
Forestry engineer, PhD
Forestry Faculty of Suceava
Str. Universitatii no. 13, Suceava, 720229, Romania
office phone +4 0230 52 29 78, ext. 531
mobile phone +4 0745 53 18 01
+4 0766 71 76 58
FAX: +4 0230 52 16 64
silvic.usv.ro
[[alternative HTML version deleted]]
Hello,
Try the following.
classes <- function(x, n){
n*findInterval(x, seq(0, ceiling(max(x)), by = n))
}
c4 <- classes(d, 4)
table(c4)
sum(table(c4))
Happy new year,
Rui Barradas
Em 31-12-2012 10:13, catalin roibu escreveu:> Dear R users,
> I want to group numerical values in classes with different size and count
> the values for each classes.
>
> My data is in this forma:
> d 15 12,5 30,4 20,5 80,4 100,5 8,2 40,5 33 21 11
> And I want the group them in classes with 4 (5,....etc) cm size like this:
> class d 16 16 32 24 84 104 12 44 36 24 12
> and final to count values for each class:
> class d n 12 2 16 2 24 2 32 1 36 1 44 1
> 84 1 104 1 Total 11
>
> Thank you!
At Mon, 31 Dec 2012 12:13:43 +0200, catalin roibu wrote:> > Dear R users, > I want to group numerical values in classes with different size and count > the values for each classes. > > My data is in this forma: > d 15 12,5 30,4 20,5 80,4 100,5 8,2 40,5 33 21 11 > And I want the group them in classes with 4 (5,....etc) cm size like this: > class d 16 16 32 24 84 104 12 44 36 24 12 > and final to count values for each class: > class d n 12 2 16 2 24 2 32 1 36 1 44 1 > 84 1 104 1 Total 11I rounded the sizes to the nearst whole cm. It's not clear to me how you want to group the elements from your description...> data = c(15, 12.5, 30.4, 20.5, 80.4, 100.5, 8.2, 40.5, 33, 21, 11) > aggregate(data, list(round(data)), length)Group.1 x 1 8 1 2 11 1 3 12 1 4 15 1 5 20 1 6 21 1 7 30 1 8 33 1 9 40 1 10 80 1 11 100 1 aggregate groups each element in the first argument according to the specified class. The third element is a function that is called on each group. Neal