[R] While loop working with TRUE/FALSE?
Patrizio Frederic
frederic.patrizio at gmail.com
Thu Feb 2 13:13:13 CET 2012
Hey Chris,
I would take advantage from the apply function:
apply(cbind(q1,q2),1,function(x)any((x[1]==w1)&(x[2]==w2)))
Regards
PF
On Thu, Feb 2, 2012 at 12:55 PM, Chris82 <rubenbauar at gmx.de> wrote:
> Thanks to Berend and the others,
>
> I've found a solution which works fine for my problem.
>
> I have not only 2 vectors, but also 4.
> Question is, if q1 and q2 is equal to w1 and w2.
> The computational time is very short, also for large data.
>
> q1 <- c(9,5,1,5)
> q2 <- c(9,2,1,5)
>
> w1 <- c(9,4,4,4,5)
> w1 <- c(9,4,4,4,5)
>
> v <- vector()
> for (i in 1:(length(q1))){
> v[i] <- any((q1[i] == w1) & (q2[i] == w2))
> }
>
>
> best regards
>
> --
> View this message in context: http://r.789695.n4.nabble.com/While-loop-working-with-TRUE-FALSE-tp4348340p4351214.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.
--
+-----------------------------------------------------------------------
| Patrizio Frederic,
| http://www.economia.unimore.it/frederic_patrizio/
+-----------------------------------------------------------------------
More information about the R-help
mailing list