How to subtract one vector from another vector in r

r

Solution

a <- 1:3
b <- 4:6

a - b
# [1] -3 -3 -3

That is a basic question, please consider reading An Introduction to R.

EDIT:

a <- 1:3
b <- 4:7
lapply(a, function(x)x-b)
# [[1]]
# [1] -3 -4 -5 -6
# [[2]]
# [1] -2 -3 -4 -5
# [[3]]
# [1] -1 -2 -3 -4

Problem

I have a vector `c <- c(1,2,3)` and another vector `d <- c(4,5,6,7)`. I want to subtract each element of `c` from each element of `d` to get a `list` of lists in R. How can I do so? Thanks.

Original source