[R] ave(x, y, FUN=length) produces character output when x is character

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Wed Dec 24 22:04:19 CET 2014


Mike,

The output is only limited by available RAM and the maximum permissible length for vectors.  And you can test it fairly easily.

vec <- sample(1:2000,10000,replace=TRUE)

Dan

Daniel J. Nordlund, PhD
Research and Data Analysis Division
Services & Enterprise Support Administration
Washington State Department of Social and Health Services


> -----Original Message-----
> From: Mike Miller [mailto:mbmiller at gmail.com] On Behalf Of Mike Miller
> Sent: Wednesday, December 24, 2014 12:44 PM
> To: Nordlund, Dan (DSHS/RDA)
> Cc: R-Help List
> Subject: Re: [R] ave(x, y, FUN=length) produces character output when x
> is character
> 
> On Wed, 24 Dec 2014, Nordlund, Dan (DSHS/RDA) wrote:
> 
> > For your character vector example, this will get you the counts.
> >
> > table(charvec)[charvec]
> >
> > Hope this is helpful,
> 
> 
> It does help, Dan!  I came up with the same idea and expanded on it a
> bit
> to work properly with other kinds of vectors:
> 
> as.vector(table( as.character(vec) )[as.character(vec)])
> 
> If there are, say, 10,000 different elements in vec, each repeated an
> average of 5-10 times, will this still work correctly?  In other words,
> the length of the table output array is unlimited, right?
> 
> Mike


More information about the R-help mailing list