sum(ifelse(x*total!=0, as.numeric(x> total), 0))
arunkumar1111 wrote > > Hi > > I have two vector > > x=c(10,30,40,50) > total=c(20,20,0,10) > > Var_exceeding_total=sum(as.numeric(x> total)) > > This will compare the vectors x and total a gives the result. > > if i want to compare only if the y > 0 . > can we apply condition in the comparison ? > -- View this message in context: http://r.789695.n4.nabble.com/comparing-vectors-with-condition-tp4382946p4383000.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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.