[R] the secret (?) language of lists

rolf at math.unb.ca rolf at math.unb.ca
Wed Nov 15 01:18:17 CET 2006


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