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? -- ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* Christopher J. Fonnesbeck Ph.D. Student Georgia Co-operative Wildlife Unit University of Georgia Athens, GA 30602 email: chris at fonnesbeck.net cfonnesb at stat.uga.edu Yahoo: fonnesbeck_chris ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
A chunk of c(mydf[1]) looks like this: [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [19] 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 [37] 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 [55] 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 [73] 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 [91] 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 They are the iteration numbers corresponding to some simulation output. I am trying to use this vector as a grouping vector for ave(). Trying to run vector(mydf[1]) gives: Error in vector(mydf[1]) : vector: cannot make a vector of mode "c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, ". So I am at a loss for what to do in order to convince this list to become a vector. My ignorance stems from the fact that I was trained in SAS. Thanks, Chris Fonnesbeck -- ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* Christopher J. Fonnesbeck Ph.D. Student Georgia Co-operative Wildlife Unit University of Georgia Athens, GA 30602 email: chris at fonnesbeck.net cfonnesb at stat.uga.edu Yahoo: fonnesbeck_chris ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._