Skip to content
Prev 171820 / 398503 Next

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

If you are in the context of a data frame (which is closest to the 
concept
of a "data set" in SAS), the 1:nrow(df) is closest to what you may look
for.

For instance:

data(iris)
.n. <- 1:nrow(iris)

You may notice that this number is not very idiomatic in R.

If you have something like:

if(_N_ > 50) then output;

in R you can simply put

iris[-(1:50),]

without using an explicit counter variable.

In the context of a matrix, the row() and col() functions may do what
you want.



Am 25.02.2009 um 15:34 schrieb justin bem: