[R] Have a function like the _n_ in R ? (Automatic count function )

2009-02-25 Thread Nash
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

Re: [R] Have a function like the _n_ in R ? (Automatic count function)

2009-02-25 Thread Shubha Vishwanath Karanth
* 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

Re: [R] Have a function like the _n_ in R ? (Automatic count function )

2009-02-25 Thread Henrique Dallazuanna
I think you can use seq function: seq(5) On Wed, Feb 25, 2009 at 9:25 AM, Nash morri...@ibms.sinica.edu.tw wrote: 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

Re: [R] Have a function like the _n_ in R ? (Automatic count function )

2009-02-25 Thread David Winsemius
The _n_ construct in SAS is most analogous to that of row names in R, accessible (and modifiable) via the row.names() function: DF - structure(list(Month = structure(c(2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L), .Label = c(Aug, July, Sept), class = factor), Week = 27:39,

Re: [R] Have a function like the _n_ in R ? (Automatic count function )

2009-02-25 Thread hadley wickham
And for completeness here's a function that returns the next integer on each call. n - (function(){ i - 0 function() { i - i + 1 i } })() n() [1] 1 n() [1] 2 n() [1] 3 n() [1] 4 n() [1] 5 n() [1] 6 ;) Hadley On Wed, Feb 25, 2009 at 8:27 AM, David Winsemius

Re: [R] Have a function like the _n_ in R ? (Automatic count function )

2009-02-25 Thread hadley wickham
On Wed, Feb 25, 2009 at 8:41 AM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: hadley wickham wrote: And for completeness here's a function that returns the next integer on each call. n - (function(){   i - 0   function() {     i - i + 1     i   } })() actually, you

Re: [R] Have a function like the _n_ in R ? (Automatic count function )

2009-02-25 Thread Gustaf Rydevik
On Wed, Feb 25, 2009 at 3:30 PM, hadley wickham h.wick...@gmail.com wrote: And for completeness here's a function that returns the next integer on each call. n - (function(){  i - 0  function() {    i - i + 1    i  } })() n() [1] 1 n() [1] 2 n() [1] 3 n() [1] 4 n() [1] 5 n()

Re: [R] Have a function like the _n_ in R ? (Automatic count function )

2009-02-25 Thread Charles C. Berry
On Wed, 25 Feb 2009, Gustaf Rydevik wrote: On Wed, Feb 25, 2009 at 3:30 PM, hadley wickham h.wick...@gmail.com wrote: And for completeness here's a function that returns the next integer on each call. n - (function(){  i - 0  function() {    i - i + 1    i  } })() n() [1] 1 n() [1] 2

Re: [R] Have a function like the _n_ in R ? (Automatic count function )

2009-02-25 Thread Wacek Kusnierczyk
hadley wickham wrote: On Wed, Feb 25, 2009 at 8:41 AM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: hadley wickham wrote: And for completeness here's a function that returns the next integer on each call. n - (function(){ i - 0 function() { i - i + 1

Re: [R] Have a function like the _n_ in R ? (Automatic count function )

2009-02-25 Thread Gustaf Rydevik
On Wed, Feb 25, 2009 at 4:43 PM, Charles C. Berry cbe...@tajo.ucsd.edu wrote: On Wed, 25 Feb 2009, Gustaf Rydevik wrote: On Wed, Feb 25, 2009 at 3:30 PM, hadley wickham h.wick...@gmail.com wrote: And for completeness here's a function that returns the next integer on each call. n -