Dear List,

I am a beginner of R and have an easy question, which I couldnt find out.

I like to exclude all rows of matrix y from matrix x (like a subset of

x, without y).

The matrix x is of the structure

>str(x)

num [1:346, 1:8] 0.055 0.6833 0.9121 0.0819 0.1223 ...

- attr(*, "dimnames")=List of 2

..$ : chr [1:346] "10357" "10815" "10829" "10885" ...

..$ : chr [1:8] "ua_mfb" "ua_mivh" "ua_mukh" "ua_schwh" ...

The matrix y is a subset of x

> str(y)

num [1:301, 1:8] 0.683 0.912 0.832 0.833 1 ...

- attr(*, "dimnames")=List of 2

..$ : chr [1:301] "10815" "10829" "12049" "13960" ...

..$ : chr [1:8] "ua_mfb" "ua_mivh" "ua_mukh" "ua_schwh" ...

Now I need a matrix w of all rows of x, which are not included in y.

w seems to obtain the dimension nrow=45, ncol=8

Example:

I have a matrix x:

> x <- matrix(1:21,ncol=3)

> rownames(x) <- c("a","b","c","d","e","f","g"); colnames(x) <-

c("V1","V2","V3")

> x

V1 V2 V3

a 1 8 15

b 2 9 16

c 3 10 17

d 4 11 18

e 5 12 19

f 6 13 20

g 7 14 21

And the subset y:

y <- x[-c(1,3,5,7),]

> y

V1 V2 V3

b 2 9 16

d 4 11 18

f 6 13 20

Now I like to exclude all rows from x, which are included in y. The result

has to be:

> w

V1 V2 V3

a 1 8 15

c 3 10 17

e 5 12 19

g 7 14 21

I tried it with:

l <- rownames(y)

> w <- x[-c(get(l)),]

Fehler in get(l) : Objekt 'b' nicht gefunden

But R couldnt find object b.

So I tried it with a loop:

> l <- rownames(y)

> w <- NULL

> for(i in l)

+ w[i] <- x[-(l),]

Fehler in -(l) : ungültiges Argument für unären Operator

But R returned: Error in (l): argument invalid

I also started experiments with get(paste()), merge, match() and subset(),

but I couldnt solve the problem jet.

I would be very thankfull for a hint (->command) or a solution.

Thanks in advance, Henning!

[hidden email]
[[alternative HTML version deleted]]

______________________________________________

[hidden email] mailing list

https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide

http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.