[R] vector problems

Mark Myatt mark at myatt.demon.co.uk
Tue Nov 6 12:09:18 CET 2001


Christopher Fonnesbeck <chris at fonnesbeck.net> writes:
>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?

See the "Operators" section of the language definition in the help
system ... data.frames are implemented as lists and the way to access
list components is to use the $ operator with the component name (e.g.
(mydf$var) or using the [[ operator with the index of the component
(e.g. mydf[[1]]). You need something like:

        unique(mydf[[1]])

I hope that helps.

Mark

--
Mark Myatt


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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