Re: [R] remove rows of a matrix by part of its row name

2018-05-22 Thread William Dunlap via R-help
I think it is simpler to use !grepl() instead of -grep() here, since subscripting with logicals works properly when there are no matches. Also, since mat is a matrix, add the argument drop=FALSE so the result is a matrix when all but one rows are omitted. E.g., > mat <- matrix(1:6, nrow=3, ncol=2

Re: [R] remove rows of a matrix by part of its row name

2018-05-22 Thread Ahmed Serag
-project.org Subject: Re: [R] remove rows of a matrix by part of its row name Hello, Please always cc the list. As for the question, yes, it does. If you want to remove just the ones with exactly 73.1 use the pattern grep("^73\\.1$", etc) Explanation: Beginning of string: ^ End

Re: [R] remove rows of a matrix by part of its row name

2018-05-22 Thread Rui Barradas
[R] remove rows of a matrix by part of its row name Hello, Use grep to get the row indices and then subset with a *negative* index to remove those rows. rn <- scan(what = character(), text = " 70/556 71.1/280 72.1/556 72.1/343 73.1/390 73.1/556 ") mat <- matrix(rnorm(6*6), nrow = 6)

Re: [R] remove rows of a matrix by part of its row name

2018-05-22 Thread Rui Barradas
Hello, Use grep to get the row indices and then subset with a *negative* index to remove those rows. rn <- scan(what = character(), text = " 70/556 71.1/280 72.1/556 72.1/343 73.1/390 73.1/556 ") mat <- matrix(rnorm(6*6), nrow = 6) row.names(mat) <- rn inx <- grep("73\\.", row.names(mat)) n

[R] remove rows of a matrix by part of its row name

2018-05-22 Thread Ahmed Serag
Dear R-experts, How can I remove a certain feature or observation by a part of its name. To be clear, I have a matrix with 766 observations as a rows. The row names are like this 70/556 71.1/280 72.1/556 72.1/343 73.1/390 73.1/556 Now I would like to remove all the rows that contain the text 7