[R] vector problems

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Nov 5 16:22:07 CET 2001


On 5 Nov 2001, Christopher Fonnesbeck wrote:

> I dont get it:
>
> > is.vector(c(mydf[1]))
> [1] TRUE
> > unique(c(mydf[1]))
> Error in unique(c(mydf[1])) : unique() applies only to vectors
> >
>
> Is it a vector or not? This stuff is driving me nuts. I'm simply trying
> to convince R that my grouping vector is actually a vector so that
> unique will work. Its just a vector of numbers, so why shouldnt it work?

Well, how about giving us some reasonable amount of information and an
example we can check over for you?

A reasonable guess is that mydf is a data frame. In that case mydf[1] is a
list, which is a vector, but not an atomic vector and so unique() does not
apply.  I don't know what you think c() does: it is strips attributes of
atomic vectors, but also works for lists, in a different way.

My guess is that you intended mydf[[1]].

> mydf <- data.frame(x=1:10, y=1:10)
> is.vector(c(mydf[1]))
[1] TRUE
> unique(c(mydf[1]))
Error in unique(c(mydf[1])) : unique() applies only to vectors
> unique(mydf[[1]])
 [1]  1  2  3  4  5  6  7  8  9 10

would seem to match the scanty evidence given.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list