[R] Error during wrapup: incorrect number of dimensions

Sam Steingold sds at gnu.org
Mon Mar 26 21:57:15 CEST 2012


when subsetting a matrix results in a single row, it is converted to a
vector, not a matrix.
how do I avoid this?

1. __GOOD__

> edges <- get.edges(g,E(g))
> edges
      [,1] [,2]
 [1,]    0    2
 [2,]    0    3
 [3,]    0    4
 [4,]    0    5
 [5,]    1    1
 [6,]    0    4
 [7,]    0    6
 [8,]    0    7
 [9,]    0    8
[10,]    0    9
[11,]    0    5
[12,]    0   10
[13,]    0   11
[14,]    0   12
[15,]    0   11
[16,]    0   13
[17,]    0   14
[18,]    0   15
[19,]    0   16
[20,]    1   17
[21,]    1   11
[22,]    0   11
> loops <- edges[,1] == edges[,2]
> loopless <- edges[!loops,]
> loopless
loopless
      [,1] [,2]
 [1,]    0    2
 [2,]    0    3
 [3,]    0    4
 [4,]    0    5
 [5,]    0    4
 [6,]    0    6
 [7,]    0    7
 [8,]    0    8
 [9,]    0    9
[10,]    0    5
[11,]    0   10
[12,]    0   11
[13,]    0   12
[14,]    0   11
[15,]    0   13
[16,]    0   14
[17,]    0   15
[18,]    0   16
[19,]    1   17
[20,]    1   11
[21,]    0   11
> unique(loopless[,1])
[1] 0 1

2. __BAD__
> edges
     [,1] [,2]     
[1,]    0    1
[2,]    0    0
Browse[1]> edges[!loops,]
[1] 0 1

why is it a vector, not a matrix?

Browse[1]> loopless
[1] 0 1
Browse[1]> loopless[,1]
Error during wrapup: incorrect number of dimensions



-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://iris.org.il http://truepeace.org
http://thereligionofpeace.com http://camera.org http://www.memritv.org
Lottery is a tax on statistics ignorants.  MS is a tax on computer-idiots.



More information about the R-help mailing list