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

2014-12-26 Thread Duncan Murdoch
On 25/12/2014 11:30 PM, Mike Miller wrote: On Thu, 25 Dec 2014, Bert Gunter wrote: You persist in failing to read the docs! the docs -- do those exclude those I have been quoting and linking to? Moreover, neither Hadley Wickham, nor anyone else, is the authoritative source for R usage

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

2014-12-25 Thread Jeff Newmiller
You have written a lot, Mike, as though we did not know it. You are not the only one with math and multiple computing languages under your belt. The point Bert made is that the concept that a matrix IS-A vector is not just an implementation detail in R... it helps the practitioner keep

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

2014-12-25 Thread Mike Miller
On Thu, 25 Dec 2014, Jeff Newmiller wrote: You have written a lot, Mike, as though we did not know it. You are not the only one with math and multiple computing languages under your belt. I'm not assuming that you and Bert don't know things, but I do expect to have a wider audience -- when

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

2014-12-25 Thread Mike Miller
On Thu, 25 Dec 2014, Mike Miller wrote: On Thu, 25 Dec 2014, Jeff Newmiller wrote: You have written a lot, Mike, as though we did not know it. You are not the only one with math and multiple computing languages under your belt. I'm not assuming that you and Bert don't know things, but I

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

2014-12-25 Thread peter dalgaard
On 25 Dec 2014, at 08:15 , Mike Miller mbmille...@gmail.com wrote: is.vector returns TRUE if x is a vector of the specified mode having no attributes other than names. It returns FALSE otherwise. So that means that a vector in R has no attributes other than names. Wrong. Read

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

2014-12-25 Thread Mike Miller
On Thu, 25 Dec 2014, peter dalgaard wrote: On 25 Dec 2014, at 08:15 , Mike Miller mbmille...@gmail.com wrote: is.vector returns TRUE if x is a vector of the specified mode having no attributes other than names. It returns FALSE otherwise. So that means that a vector in R has no

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

2014-12-25 Thread Duncan Murdoch
On 25/12/2014 1:57 PM, Mike Miller wrote: On Thu, 25 Dec 2014, peter dalgaard wrote: On 25 Dec 2014, at 08:15 , Mike Miller mbmille...@gmail.com wrote: is.vector returns TRUE if x is a vector of the specified mode having no attributes other than names. It returns FALSE otherwise. So

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

2014-12-25 Thread Bert Gunter
On Thu, Dec 25, 2014 at 12:41 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: Would you say a cube contains a polygon, or a cube is a polygon? Neither, actually. I'd say a cube is a polyhedron or a square is a polygon. :-) But point taken, of course. Cheers, Bert Bert Gunter

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

2014-12-25 Thread Mike Miller
On Thu, 25 Dec 2014, Duncan Murdoch wrote: On 25/12/2014 1:57 PM, Mike Miller wrote: I do think I get what is going on with this, but why should I buy into this conceptualization? Why is it better to say that a matrix *is* a vector than to say that a matrix *contains* a vector? The latter

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

2014-12-25 Thread Duncan Murdoch
On 25/12/2014 3:59 PM, Bert Gunter wrote: On Thu, Dec 25, 2014 at 12:41 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: Would you say a cube contains a polygon, or a cube is a polygon? Neither, actually. I'd say a cube is a polyhedron or a square is a polygon. :-) But point taken,

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

2014-12-25 Thread Gabor Grothendieck
On Thu, Dec 25, 2014 at 1:57 PM, Mike Miller mbmille...@gmail.com wrote: I do think I get what is going on with this, but why should I buy into this conceptualization? Why is it better to say that a matrix *is* a vector than to say that a matrix *contains* a vector? The latter seems to be the

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

2014-12-25 Thread Mike Miller
On Thu, 25 Dec 2014, Mike Miller wrote: I was going to ask a question about it how to test that an object is a vector, but then I found this: is.vector() does not test if an object is a vector. Instead it returns TRUE only if the object is a vector with no attributes apart from names. Use

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

2014-12-25 Thread Bert Gunter
You persist in failing to read the docs! Moreover, neither Hadley Wickham, nor anyone else, is the authoritative source for R usage (other than for the (many!) packages he, himself has authored). R's Help pages and manuals -- and ultimately the source code -- are the only such source. ?factor

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

2014-12-25 Thread Mike Miller
On Thu, 25 Dec 2014, Bert Gunter wrote: You persist in failing to read the docs! the docs -- do those exclude those I have been quoting and linking to? Moreover, neither Hadley Wickham, nor anyone else, is the authoritative source for R usage (other than for the (many!) packages he, himself

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

2014-12-24 Thread Mike Miller
R 3.0.1 on Linux 64... I was working with someone else's code. They were using ave() in a way that I guess is nonstandard: Isn't FUN always supposed to be a variant of mean()? The idea was to count for every element of a factor vector how many times the level of that element occurs in the

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

2014-12-24 Thread Bert Gunter
You said: The elements of the first vector are irrelevant because they are only counted, so we should get the same result if it were a character vector, but we don't: You don't get to invent your own rules! ?ave -- always nice to read the Help docs **before posting** -- clearly states that the x

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

2014-12-24 Thread Nordlund, Dan (DSHS/RDA)
-Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Mike Miller Sent: Wednesday, December 24, 2014 11:31 AM To: R-Help List Subject: [R] ave(x, y, FUN=length) produces character output when x is character R 3.0.1 on Linux 64... I was working

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

2014-12-24 Thread Mike Miller
On Wed, 24 Dec 2014, Bert Gunter wrote: You said: The elements of the first vector are irrelevant because they are only counted, so we should get the same result if it were a character vector, but we don't: You don't get to invent your own rules! ?ave -- always nice to read the Help docs

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

2014-12-24 Thread Mike Miller
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:

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

2014-12-24 Thread Nordlund, Dan (DSHS/RDA)
State Department of Social and Health Services -Original Message- From: Mike Miller [mailto:mbmil...@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

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

2014-12-24 Thread William Dunlap
ave( as.character(1:5), gl(2,2,5), FUN=length ) [1] 3 3 2 2 3The output has character type, but it is supposed to be a collection of vector lengths. ave() uses its first argument, 'x', to set the length of its output and to make an initial guess at the type of its output. The return value

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

2014-12-24 Thread Mike Miller
On Wed, 24 Dec 2014, Mike Miller wrote: Also, regarding the sacred text, x A numeric. is a bit terse. The same text later refers to length(x), so I suspect that A numeric is short for A numeric vector, but that might not mean a vector of 'numeric' type. I just realized that numeric type

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

2014-12-24 Thread Jeff Newmiller
But all numeric types in R are vectors. So although it might be a good idea to be redundant to aid beginners, the phrase a numeric is accurate. --- Jeff NewmillerThe . . Go Live...

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

2014-12-24 Thread Mike Miller
On Wed, 24 Dec 2014, Jeff Newmiller wrote: On December 24, 2014 6:49:47 PM PST, Mike Miller mbmille...@gmail.com wrote: On Wed, 24 Dec 2014, Mike Miller wrote: Also, regarding the sacred text, x A numeric. is a bit terse. The same text later refers to length(x), so I suspect that A numeric

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

2014-12-24 Thread Bert Gunter
You are again misinterpreting because you have not read the docs, although this time I will grant that they are to some extent misleading. First of all, a matrix _IS_ a vector: a - matrix(1:4, 2,2) a[3] ## vector indexing works because it is a vector [1] 3 In fact, a matrix (or array) is a

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

2014-12-24 Thread Mike Miller
On Wed, 24 Dec 2014, Bert Gunter wrote: You are again misinterpreting because you have not read the docs, although this time I will grant that they are to some extent misleading. First of all, a matrix _IS_ a vector: a - matrix(1:4, 2,2) a[3] ## vector indexing works because it is a vector