as.vector does not take mode="NUMERIC", so re-check the help page.
Most of the error messages stem from that user error.
First convert to a matrix, then to a vector. You cannot convert a data
frame (a list) directly to a numeric vector. as.vector(as.matrix(my.df))
should work for a data frame with all numeric columns. Otherwise consider
numerical.matrix or data.matrix.
On Sun, 14 Sep 2003, Chushu Gu wrote:
> Thanks for the two replys, that settled my question.
>
> And how to convert the data frame to vector
>
> I got this from s-plus
>
> >m.all<- as.vector(WHO[WHO[,2] == "Argentina" & WHO[,3] == 1980 & WHO[,4] ==
> >1 & WHO[,5] == "B00", 6:23],mode="NUMERIC")
> > m.all
> unknown(q1 = 0.0447109294728576, q2 = 0.00269321320916402, q3 =
> 0.00261711593823606, q4 = 0.00539140997091196, q5 = 0.0073341300603907, q6 =
> 0.00815965233195142, q7 = 0.0100250372003027, q8 = 0.0148791752125287, q9 =
> 0.0239547791128666, q10 = 0.038536280096176, q11 =
> 0.0563545018963813, q12 = 0.0831131954707847, q13 = 0.123400910260711, q14 =
> 0.174278618664434, q15 = 0.255247405299222, q16 =
> 0.683480775000682, q17 = NA, q18 = NA)
> > m.all *8
> Error in m.all * 8: Non-numeric first operand
> > m.all[1]
> Error in m.all[1]: Objects of mode unknown can't have length >0
> >m.all<- as.vector(WHO[WHO[,2] == "Argentina" & WHO[,3] == 1980 & WHO[,4] ==
> >1 & WHO[,5] == "B00", 6:23])
> > as.double(m.all)
> Error in as.double: Cannot coerce mode list to double: list(..
>
>
> What I want to get is just a vector, all are numeric values. I need a neat
> and clean way to do that.
>
> Thanks again
>
> Chushu Gu
--
Brian D. Ripley, ripley@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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
|