What will be the result of multiplying two vectors in R ?

Question

They have different lengths.

in progress 0
Dhruv2301 55 years 2 Answers 875 views Great Grand Master 0

Answers ( 2 )

  1. 1) If same length

    a <- c(1,2,3)
    b <- c(4,5,6)
    a*b
    OUTPUT :
    4,10,18

    2) If unequal lengths
    The shorter vector will be recycled in order to match the longer vector.

    a <- c(1,2,3,4,5,6)
    b <- c(4,5,6)

    OUTPUT:
    4, 10, 18, 16, 25, 36

  2. #multiplication of vectors of unequal length
    A <-c(1,2,0,4)
    B<-c(3,6)
    A*B will be ( 3,12,0,24).
    This is known as element recycling .

Leave an answer

Browse
Browse