[R] I need a very specific unique like function and I don't know even how to properly call this
Phil Spector
spector at stat.berkeley.edu
Tue Nov 23 00:20:56 CET 2010
Given a vector, x, we can test if the value above
it is equal to itself with
abv = c(FALSE,x[-l] == x[-1])
and if the value below is equal to itself with
blw = c(x[-l] == x[-1],FALSE)
So, for your problem:
> abv = c(FALSE,dat[,2][-l] == dat[,2][-1])
> blw = c(dat[,2][-l] == dat[,2][-1],FALSE)
> dat[!(abv & blw),]
[,1] [,2]
[1,] 3 7
[2,] 6 5
[3,] 5 5
[4,] 8 4
[5,] 7 4
[6,] 0 6
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spector at stat.berkeley.edu
On Mon, 22 Nov 2010, madr wrote:
>
> consider this matrix:
>
> [,1] [,2]
> [1,] 3 7
> [2,] 6 5
> [3,] 7 5
> [4,] 3 5
> [5,] 7 5
> [6,] 5 5
> [7,] 8 4
> [8,] 2 4
> [9,] 7 4
> [10,] 0 6
>
> I need to delete all rows where column 2 above and below has the same value,
> so the effect would be:
>
> [,1] [,2]
> [1,] 3 7
> [2,] 6 5
> [6,] 5 5
> [7,] 8 4
> [9,] 7 4
> [10,] 0 6
>
> is there a built in function for that kind of operation or I must write one
> from scratch ?
> Is there a name for that kind of operation ?
> --
> View this message in context: http://r.789695.n4.nabble.com/I-need-a-very-specific-unique-like-function-and-I-don-t-know-even-how-to-properly-call-this-tp3054427p3054427.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list