It was a great help Phil!

but I was in some doubts with the cut command, so I develop  this program
using the Ntil formula
in this case vigntil or NTIL(20) and NTIL(10) respectively, but definitely
thanks again!!!

lk<-c(12,23,34,13,45,56)
> cut(lk,quantile(lk,(0:20)/20),labels=FALSE,include.lowest=TRUE)
[1]  1  8 12  4 16 20
> vigintiles(lk)
[1]  1  8 12  4 16 20
> vigintiles<-function(mtx)
{ #the input must be a numeric list or matrix
   Dk<-quantile(mtx, probs = c(5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55,
60, 65, 70, 75, 80, 85, 90, 95, 100)/100)

   maxlista<- length(mtx)
   mtxr<- mtx
   mtxmin<- min(mtx)
   mtxmax<- max(mtx)
   ind<- 1

   while(ind<maxlista+1)
    {
       indicador<-2
       iNtil<-1

while(iNtil<indicador)
{
if ((iNtil==1) && (mtxmin <= mtx[ind]) && (mtx[ind] < Dk[iNtil]) )
        {
    mtxr[ind]<-iNtil # iNtil=1
  indicador<-iNtil
        }
       else
       if ((iNtil==20) && (mtx[ind] <= Dk[iNtil-1]) && (mtx[ind] <= mtxmax
))
        {
  mtxr[ind]<-iNtil # iNtil=20
  indicador<-iNtil
        }
       else
       if ((mtx[ind] >= Dk[iNtil-1]) && (mtx[ind] <= Dk[iNtil]))
         {
   mtxr[ind]<-iNtil
   indicador<-iNtil
         }
           iNtil <- iNtil +1
           indicador<- indicador+1
         }
  ind<- ind+1
}
   return(mtxr)
}
>




lk<-c(12,23,34,13,45,56)
> cut(lk,quantile(lk,(0:10)/10),labels=FALSE,include.lowest=TRUE)
[1]  1  4  6  2  8 10
> deciles(lk)
[1]  1  4  6  2  8 10
> deciles<- function(mtx)
{
   Dk<-quantile(mtx, probs = c(10,  20, 30, 40, 50, 60, 70, 80, 90,
100)/100)

   maxlista<- length(mtx)
   mtxr<- mtx
   mtxmin<- min(mtx)
   mtxmax<- max(mtx)
   ind<- 1

   while(ind<maxlista+1)
    {
       indicador<-2
       idecil<-1

while(idecil<indicador)
{
if ((idecil==1) && (mtxmin <= mtx[ind]) && (mtx[ind] < Dk[idecil]) )
        {
    mtxr[ind]<-idecil # idecil=1
  indicador<-idecil
        }
       else
       if ((idecil==10) && (mtx[ind] <= Dk[idecil-1]) && (mtx[ind] <= mtxmax
))
        {
  mtxr[ind]<-idecil # idecil=10
  indicador<-idecil
        }
       else
       if ((mtx[ind] >= Dk[idecil-1]) && (mtx[ind] <= Dk[idecil]))
         {
   mtxr[ind]<-idecil
   indicador<-idecil
         }
           idecil <- idecil +1
           indicador<- indicador+1
         }
  ind<- ind+1
}
   return(mtxr)
}






Best regards,
-----------------------------------------------
Arturo Coral Alamo
Business Researcher Team
SOLUCION ESTRATEGICA Inc.
Genera competitividad en tu empresa
M?vil: (+511) 988 567 000
Fijo:   (+511) 528 50 44
www.seincperu.com


On Wed, Jun 16, 2010 at 6:22 PM, Phil Spector <spec...@stat.berkeley.edu>wrote:

> Arturo -
>    Something like
>
> cut(x,quantile(x,(0:10)/10),labels=FALSE,include.lowest=TRUE)
>
> should give you what you want.
>
>                                        - Phil Spector
>                                         Statistical Computing Facility
>                                         Department of Statistics
>                                         UC Berkeley
>                                         spec...@stat.berkeley.edu
>
>
> On Wed, 16 Jun 2010, J. Arturo Coral Alamo wrote:
>
>  Hello comunity,
>>
>> I'm trying to find a similar function as decile of SPSS, NTILES (10)
>> some of you know about  that, I will appreciate your help in advance.
>>
>> In SPSS
>> VARIABLES=Sales  (A) /NTILES (10) /PRINT=NO
>>
>> for example if I have Next data input:
>>
>> case IdCust Sales Profit 1 265 140.81 314.31 2 266 1778.96 408.32 3 267
>> 2663.66 820.85 4 268 2994.14 913.73 5 269 2185.58 686.64 6 271 105.21
>> 18.94
>>
>>
>> Output must be:
>>
>> case IdCust Sales Profit Ntil-Sales Ntil-Profi 1 265 140.81 314.31 2 2 2
>> 266
>> 1778.96 408.32 4 4 3 267 2663.66 820.85 8 8 4 268 2994.14 913.73 10 10 5
>> 269
>> 2185.58 686.64 6 6 6 271 105.21 18.94 1 1
>>
>>
>>
>>
>> Best regards,
>> -----------------------------------------------
>> Arturo Coral Alamo
>> Business Researcher Team
>> SOLUCION ESTRATEGICA Inc.
>> Genera competitividad en tu empresa
>> M?vil: (+511) 988 567 000
>> Fijo:   (+511) 528 50 44
>> www.seincperu.com
>>
>>        [[alternative HTML version deleted]]
>>
>>
>>

        [[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