Hi R-users,
 
I would like to transform my data using gamma, my data are ahll, bhall and dp1 
as shown below:
 
> ahall
     ah1  ah2  ah3  ah4  ah5  ah6  ah7  ah8  ah9 ah10 ah11 ah12
[1,] 0.9 1.01 1.24 1.85 1.85 2.45 3.67 3.02 3.06 2.33 1.86 0.96
 
> bhall 
       bh1   bh2   bh3   bh4  bh5   bh6   bh7   bh8   
bh9  bh10  bh11  bh12
[1,] 48.39 44.26 37.34 29.93 33.5 26.54 20.26 25.73 20.14 31.57 27.38 50.32
 
> dp1
         d1    d2    d3    d4    d5    d6    d7    
d8    d9   d10   d11   d12
 [1,]  49.7 141.6 119.7  27.2  56.0  58.1  59.2  22.8  28.0  69.9   
5.3   3.3
 [2,]  21.8  32.3  30.0  44.5  37.7  49.3  29.0  49.6  79.2  28.8  
26.5  44.2
 [3,]   5.6   3.3   6.3  33.7  56.1  37.9  54.7  77.9  24.9  
98.6  42.5 157.5
 [4,]  24.2  28.5 175.5  73.2 153.7 201.4  62.9  67.6  36.7  47.8  
87.1   1.0
 [5,]   0.8  55.1  66.3  98.2  16.7  99.0  54.1  91.2  34.5  45.7  
33.3  22.1
….
[55,]  43.0   0.0 131.0  31.6  55.8  31.8  17.0  10.0  45.4   
9.2   2.8  21.8
[56,]   1.4  43.4  52.4  72.2 126.8  66.8 101.6 144.2  82.2  85.0  
37.4  55.4
[57,] 167.4 194.0  17.4  38.0   9.2  11.6 110.2 126.4  68.8  74.0   
9.2  18.2
[58,]  11.4   8.2  46.6  49.6  84.2  68.2  48.6 160.6  31.6  94.8  
62.6  67.6
 
I try to write this code and try run it but got error message:
 
trans_dt <- function(dt,a,b)
{ trans  <- vector(length=12, mode="numeric")
  n <- ncol(dt)
  for (i in 1:n)
  {  trans[i] <- transform(dt[,i],newdt=pgamma(dt[,i],shape= 
a[1,i],scale=b[1,i])) }
  trans
}
 
> trans_dt(dp1,ahall,bhall)
Error in pgamma(dt[, i], shape = a[1, i], scale = b[1, i]) : 
  object "i" not found

 
Here are the output that I want:
 
   X_data      newdt
1    49.7 0.68457469
2    21.8 0.41338124
3     5.6 0.14140426
4    24.2 0.44446935
5     0.8 0.02570607
6    32.0 0.53374025
7    88.9 0.86499757
…
 
Thank you so much for any help given.


      
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to