Explore Courses Blog Tutorials Interview Questions
0 votes
in R Programming by (50.2k points)

I want to count how many difference between x and y where x and y from binomial distribution. I have done the following code but I want more simpler way:

x <- rbinom(20, 1, 0.7)

y <- rbinom(20, 1, 0.4)

z <- 0

for (i in 1:20){

  if (x[i]!=y[i]){

    z <- z+1




1 Answer

0 votes
by (108k points)

In R programming, if you want the desired output then do refer to the following cod as the following code is a Boolean expression that has been vectorized across x and y values:

sum(x != y)

Browse Categories