# [R] Filter Dataframe for Alarm for particular column(s).

arun smartpink111 at yahoo.com
Fri Jul 5 21:16:40 CEST 2013

```Hi,
May be this helps:
If you had showed your solution, it would be easier to compare.

res<-data.frame(lapply(sapply(MyDF[,c(2,4)],function(x) {x1<-which(c(0,diff(x))<0);x1[length(x1)==0]<-0;x1}),`[`,1))
res
#  TNH BIX
#1   3   9

#Speed

set.seed(24)
MyDFNew<- data.frame(TNH=sample(0:1,1e6,replace=TRUE),BIX=sample(0:1,1e6,replace=TRUE))
system.time(res1<-data.frame(lapply(sapply(MyDFNew,function(x) {x1<-which(c(0,diff(x))<0);x1[length(x1)==0]<-0;x1}),`[`,1)))
#   user  system elapsed
#  0.364   0.000   0.363

res1
#  TNH BIX
#1   7   2
MyDFNew[1:10,]
#   TNH BIX
#1    0   1
#2    0   0
#3    1   1
#4    1   1
#5    1   0
#6    1   0
#7    0   1
#8    1   1
#9    1   1
#10   0   0

A.K.

Hi,

Hi here i have a dataframe called MyDF.

a<-c(1,1,1,1,1,0,0,0,1,1)
b<-c(1,1,0,1,1,0,0,0,1,1)
c<-c(1,1,1,1,1,1,1,0,1,1)
d<-c(1,1,1,1,1,1,1,1,0,1)
MyDF<-data.frame(DWATT=a,TNH=b,CSGV=c,BIX=d)

My requirement is, here i need a function - to get for a
particular row number(s), when particular column(s) value change from
one-to-zero  (for the first change). Suppose there is no change is
happening then it should return "Zero"

For example,  Using MyDF,

DWATT TNH CSGV BIX
1   1    1   1
1   1    1   1
1   0    1   1
1   1    1   1
1   1    1   1
0   0    1   1
0   0    1   1
0   0    0   1
1   1    1   0
1   1    1   1

Here i want to know, the row number where TNH-column and BIX-column values change happening from one-to-zero for the first time.

Note:- Suppose there is no change is happening then it should return "Zero"

Answer should be  a dataframe with single row.
So here answer should return a dataframe like this.

TNH  BIX
----    ------
3      9

i used some ways to get a solution using loops. But there is a bulk files with bulk rows to process.
So performace is most important. Could someone please suggest better ideas ?

Thanks,
Antony.

```