[R] compare two rows in same column in data farme

arun smartpink111 at yahoo.com
Thu Jan 2 16:58:54 CET 2014

May be this helps:
dat1 <- read.table(text="line start
  A1 21
  A2 22
  A3 23
  B4 19
  B2 24
  B6 12",sep="",header=TRUE,stringsAsFactors=FALSE)
dat1[c(TRUE,diff(dat1[,2]) >0 ),]
#  line start
#1   A1    21
#2   A2    22
#3   A3    23
#5   B2    24

On Thursday, January 2, 2014 10:54 AM, raz <barvazduck at gmail.com> wrote:

I would like to compare row data in the same column through a data frame
and remove all rows that do not fit the criteria.
for example if I have the following data frame:
  line start  A1 21  A2 22  A3 23  B4 19  B2 24  B6 12
I would like to compare the 'start' value of each line to the value of next
line (22-21,23-22,19-23,24-19,12-24) and if it is smaller then to remove
the line so that at the end I would get
  line start  A1 21  A2 22  A3 23  B2 24



    [[alternative HTML version deleted]]

R-help at r-project.org mailing list
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