On 2012-03-26 12:57, Sam Steingold wrote:
when subsetting a matrix results in a single row, it is converted to a
vector, not a matrix.
how do I avoid this?

Check ?"[" and note the 'drop=' argument.

Peter Ehlers


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




______________________________________________
[email protected] 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.

Reply via email to