I am trying to count the number of occurrences of species (distributed along an altitude gradient) in 'class' of altitudes.
Here is the original data frame :
tab
R sp N Hauteur Alt Plot Quadrat Microhab Cover
1 R2 B 1 0-50cm 350 P1 Q1 TA 50
2 R2 D 1 0-50cm 350 P1 Q1 TA 50
3 R3 A 2 0-50cm 550 P1 Q1 TA 95
4 R3 C 1 0-50cm 550 P1 Q1 TA 95
5 R3 B 3 0-50cm 550 P1 Q1 TA 95
6 R3 D 4 0-50cm 550 P1 Q1 TA 95
7 R4 C 3 0.5-1m 350 P1 Q1 TB 50
8 R4 A 4 0.5-1m 350 P1 Q1 TB 50
9 R4 E 2 0.5-1m 350 P1 Q1 TB 50
10 R4 D 3 0.5-1m 350 P1 Q1 TB 50
11 R4 B 4 0.5-1m 350 P1 Q1 TB 50
and here is what I would like to obtain :
head(parametres)
SP Altmin Altmax Altmoy nb_350.549 nb_550.749 [...] %_350.549m
A 350 550 450 1 0 ... 50
B 350 550 416.67 2 1 ... 33.3
C 350 550 450 1 0 ... 50
For that I manage to get the firts 4 columns ("SP","Altmin","Altmax","Altmoy"). But I don't manage to get the number of occurrence by 'class of altitude' (e.g. "nb_350.549"), nor the percentage of representativeness of each altitude class among all, regarding the number of occurrence of each species (e.g. "%_350.549) - which is in fact = nb.occ.SP(A) / nb_350.549 *100
Here is my script :
parametres<-ddply(tab,.(sp),function(esp){
+ summarise(esp,
+ Altmin=min(Alt),
+ Altmax=max(Alt),
+ Altmoy=mean(Alt),
+ )})
Any idea?
Thanks!
R.