[R] why as.vector can't make x to be a vector?

Duncan Murdoch murdoch.duncan at gmail.com
Sun Dec 15 13:12:13 CET 2013


On 13-12-15 6:48 AM, 水静流深 wrote:
>> x=read.table(text="
> +   Qtr1 Qtr2 Qtr3 Qtr4
> + 2010  1.8  8.0  6.0  3.0
> + 2011  2.0 11.0  7.0  3.5
> + 2012  2.5 14.0  8.0  4.2
> + 2013  3.0 15.2  9.5  5.0",sep="",header=TRUE)
>> x
>       Qtr1 Qtr2 Qtr3 Qtr4
> 2010  1.8  8.0  6.0  3.0
> 2011  2.0 11.0  7.0  3.5
> 2012  2.5 14.0  8.0  4.2
> 2013  3.0 15.2  9.5  5.0
>> as.vector(x)
>       Qtr1 Qtr2 Qtr3 Qtr4
> 2010  1.8  8.0  6.0  3.0
> 2011  2.0 11.0  7.0  3.5
> 2012  2.5 14.0  8.0  4.2
> 2013  3.0 15.2  9.5  5.0
>> class(as.vector(x))
> [1] "data.frame"

Data frames are lists, which are already vectors.

Duncan Murdoch



More information about the R-help mailing list