[R] (no subject)

Benjamin Stewart petie_stewart at hotmail.com
Wed Apr 21 19:27:42 CEST 2010


I've got a problem with the sparseby command (reshape
library), and I have reached the peak of my R knowledge (it isn't really that
high).

 

I have a small data frame of 23 rows and 15 columns, here
is a subset, the first four columns are factors and the rest are numeric (only
one, line54 is provided).

 

   bearID YEAR
Season SEX      line54

5    1900    8     
3   0  16.3923519

11   2270    5     
1   0 233.7414014

12   2271    5     
1   0 290.8207652

13   2271    5     
2   0 244.7820844

15   2291    5     
1   0   0.0000000

16   2291    5     
2   0  14.5037795

17   2291    6     
1   0   0.0000000

18   2293    5     
2   0 144.7440752

19   2293    5     
3   0   0.0000000

20   2293    6     
1   0  16.0592270

21   2293    6     
2   0  30.1383426

28   2298    5     
1   0   0.9741067

29   2298    5     
2   0   9.6641018

30   2298    6     
2   0   8.6533828

31   2309    5     
2   0  85.9781303

32   2325    6     
1   0 110.8892153

35   2331    6     
1   0  26.7335562

44   2390    7     
2   0   7.1690620

45   2390    8     
2   0  44.1109897

46   2390    8     
3   0 503.9074898

47   2390    9     
2   0   8.4393660

54   2416    7     
3   0  48.6910907

58   2418    8      2  
0   5.7951139

 

Sparseby works fine when I try to calculate mean

 

>sparseby(mF[1:5], mF$Season, mean)

 

  mF$Season bearID
YEAR Season SEX    line54

1         1     NA  
NA     NA   0 
84.90228

2         2     NA  
NA     NA   0 
54.90713

3         3     NA  
NA     NA   0 142.24773

 

But it goes nuts when looking for max or min

 

> sparseby(mF[5:6], mF$Season, max)

  mF$Season
structure(c(2169.49621795108, 1885.22677689026, 2492.17544685464

1         1                                                        
2169.496

2         2                                                        
1885.227

3         3                                                        
2492.175

 

Any ideas? All I want is to calculate create three
data.frames, mean, min and max.

 

Thanks,

 

Ben Stewart

  		 	   		  



More information about the R-help mailing list