Skip to content

count number of groups

6 messages · andrija djurovic, Charles Determan Jr, R. Michael Weylandt

#
length(unique(ID))

Michael
On Fri, May 25, 2012 at 11:38 AM, Charles Determan Jr <deter088 at umn.edu> wrote:
#
You'll have to be a little trickier if you want it to be smart and
pick up the name: [or I'm missing something obvious]

yourFunc <- function(x){
   dsx <- deparse(substitute(x))
   x <- length(unique(x))
   names(x) <- dsx
   x
}

yourFunc(ID)

yourFunc(ID^2)

yourFunc(ID[ID==2])


etc.

Hope this helps,
M
On Fri, May 25, 2012 at 12:42 PM, Charles Determan Jr <deter088 at umn.edu> wrote: