Write a R Program to Two vector Variables (Addition, Subtraction, Multiplication, Division, Mod, Coefficient)

Write a R Program to Two vector Variables (Addition, Subtraction, Multiplication, Division, Mod, Coefficient)

x <- c(2 ,3 ,4 ,4)
y <-c(3, 4 ,5 ,6)
print (x+y)
print(x-y)
print(x*y)
print(x/y)
print(x%%y)
print(x^y)
or
sum(x,y)
prod(x,y)

Output:

$Rscript main.r
[1] 5 7 9 10
[1] -1 -1 -1 -2
[1] 6 12 20 24
[1] 0.6666667 0.7500000 0.8000000 0.6666667
[1] 2 3 4 4
[1] 8 81 1024 4096
[1] 31
[1] 34560

No Comments

Post a Reply