Hi Arun,

 

Thanks for the solution it  really works !. But how can we avoid even lappy() and  sappy().

Actually any way to do with ts() ?

 

Thanks,

Antony.

 

From: arun kirshna [via R] [mailto:ml-node+s789695n4670970h8@n4.nabble.com] 
Sent: Saturday, July 06, 2013 12:54 AM
To: Akkara, Antony (GE Power & Water, Non-GE)
Subject: Re: Filter Dataframe for Alarm for particular column(s).

 

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. 

______________________________________________ 
[hidden email] 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. 



________________________________

If you reply to this email, your message will be added to the discussion below:

http://r.789695.n4.nabble.com/Filter-Dataframe-for-Alarm-for-particular-column-s-tp4670950p4670970.html 

To unsubscribe from Filter Dataframe for Alarm for particular column(s)., click here <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4670950&code=YW50b255LmFra2FyYUBnZS5jb218NDY3MDk1MHwxNTUxOTQzMDI5> .
NAML <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>  





--
View this message in context: http://r.789695.n4.nabble.com/Filter-Dataframe-for-Alarm-for-particular-column-s-tp4670950p4671203.html
Sent from the R help mailing list archive at Nabble.com.
	[[alternative HTML version deleted]]

