[R] Indexing problem with matrix
Bert Gunter
gunter.berton at gene.com
Fri Jul 22 18:34:32 CEST 2011
See the "drop" argument (and link) in ?"["
-- Bert
On Fri, Jul 22, 2011 at 9:46 AM, Bogaso Christofer
<bogaso.christofer at gmail.com> wrote:
> Dear all, assume I have a matrix with just 1 row. Now suppose I want to
> fetch 1st few rows from that matrix, however resulting object becomes
> vector. Here is 1 such example:
>
>
>
>> matrix(1:5, 1)
>
> [,1] [,2] [,3] [,4] [,5]
>
> [1,] 1 2 3 4 5
>
>>
>
>> matrix(1:5, 1)[,-1]
>
> [1] 2 3 4 5
>
>
>
> Can somebody point me how to keep resulting object as matrix with same row?
> Ofcourse I again make legitimate matrix with something like as.matrix()
> function. However I believe there must be some more directly way with
> indexing in some better way!
>
>
>
> Thanks,
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."
-- Maimonides (1135-1204)
Bert Gunter
Genentech Nonclinical Biostatistics
467-7374
More information about the R-help
mailing list