> temp=data.frame(a=c(4,3,2,6),b=c(7,4,2,4)) > temp a b 1 4 7 2 3 4 3 2 2 4 6 4 > temp$counter=1:nrow(temp) > temp a b counter 1 4 7 1 2 3 4 2 3 2 2 3 4 6 4 4
Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Nash Sent: Wednesday, February 25, 2009 5:55 PM To: r-help Subject: [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 - morri...@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. This e-mail may contain confidential and/or privileged i...{{dropped:10}} ______________________________________________ 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.