What will be the result of multiplying two vectors in R ?
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
Answers ( 2 )
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
#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 .