R is more flexible that SAS. You have many functions for loop e.g. for, while, repeat. You also have dim and length functions to get objects dimensions.

i<-0
dat<-matrix(c(1, runif(1), .Random.seed[1]),nr=1)
repeat{
    i=i+1
    dat<-rbind(dat, matrix(c(1+i, runif(1), .Random.seed[1]),nr=1))
    if (i==4) break
}

colnames(dat)<-c("counter", "x","seed")
dat

 Justin BEM
BP 1917 Yaoundé
Tél (237) 99597295
(237) 22040246 




________________________________
De : Nash <morrison@ibms.sinica.edu.tw>
À : r-help <r-help@r-project.org>
Envoyé le : Mercredi, 25 Février 2009, 13h25mn 18s
Objet : [R] Have a function like the "_n_" in R ? (Automatic count function )


Have the counter function in R ?

if we use the software SAS

/*** SAS Code **************************/
data tmp(drop= i);
retain seed x 0;
do i = 1 to 5;
    call ranuni(seed,x);
    output;
end;
run;

data new;
counter=_n_;  ***** this keyword _n_ ****;
set tmp;
run;

/*
_n_ (Automatic variables)
are created automatically by the DATA step or by DATA step statements.
*/

/*** Output ********************************
counter        seed            x
1    584043288            0.27197
2    935902963            0.43581
3    301879523            0.14057
4    753212598            0.35074
5    1607264573    0.74844

********************************************/

Have a function like the "_n_" in R ?


--
Nash - morrison@ibms.sinica.edu.tw

______________________________________________
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.



      
	[[alternative HTML version deleted]]


