[R] the secret (?) language of lists
Berton Gunter
gunter.berton at gene.com
Wed Nov 15 17:15:22 CET 2006
>From c()'s Help docs:
"The default method combines its arguments to form a vector. ....
The output type is determined from the highest type of the components in the
hierarchy NULL < raw < logical < integer < real < complex < character < list
< expression. "
Perhaps this could be clearer, but I read this as saying that if M is a
matrix, c(M) should give a vector of type that of the type of M. Peter D's
idiom is perhaps too clever or arcane, but nevertheless documented.
As usual, Brian Ripley's comment is pertinent: as.vector() makes the silent
coercion explicit.
Bert Gunter
Nonclinical Statistics
7-7374
-----Original Message-----
From: rolf at math.unb.ca [mailto:rolf at math.unb.ca]
Sent: Tuesday, November 14, 2006 4:18 PM
To: gunter.berton at gene.com
Cc: jspies at nd.edu; p.dalgaard at biostat.ku.dk; r-help at stat.math.ethz.ch
Subject: Re: [R] the secret (?) language of lists
Berton Gunter wrote:
> - c() removes attributes
>
> ** Documented in c()'s Help file
***REALLY*** ??? Where? The only use of the word ``attribute'' in
the help file is in ``See Also: 'unlist' and 'as.vector' to produce
attribute-free vectors.''
Unless you already knew the fact that when m is a matrix c(m)
gives a vector strung out in column order, you'd be very unlikely to
discern that fact from the help file for c(). The only hint is that
the output is described as being a vector. This is not exactly
spoon-feeding the user. (Especially in view of the fact that a
matrix ***is*** a vector --- with a dim attribute. Or so you
keep telling us.)
The help file talks about catenation (which is the essential role of
c()) and expounds at length about the type of the result. The user
is going to think in terms of c(v1,v2,v3), usw, where v1, v2 and v3
are ``genuine'' vectors''; it would never occur to him or her to
apply c() to a matrix.
There is no way on God's green earth that even the most diligent of
neophytes is going to work out that c() has the effect on matrices
that it does. EVEN IF the poor neophyte is so sophisticated as to
have absorbed the idea that a matrix is a vector with a dim
attribute. Which is perhaps a neat trick in designing data
structures but is not, to put it mildly, intuitive.
All too often it is useful to RTFM only if you already know the
answer to your question.
cheers,
Rolf Turner
rolf at math.unb.ca
More information about the R-help
mailing list