I am trying to find the difference between many pairs of numbers.
These numbers are in two vectors of unequal length. For example,
a<- c(1:5)
b<- c(1:10)
Now, I need some way of calculating the a[[1]] - b and then a[[2]] - b and so on until a[[5]] - b. Each of these calculations should result in a vector, 10 numbers long.
Each of these vectors of differences should be stored together as columns in a dataframe. The first column should be the position of ´b´ subtracted and the subsequent columns should be titled with the position of ´a´ (so there are 5 columns and 10 rows).
a[1] a[2] ... a[5]
b[1]
b[2]
...
b[10]
I am very new to writing functions in R. I am also new to using the *apply group of functions. I have been trying to combine what I have learned about writing functions and the *apply group of functions to solve this but it just isn´t happening yet. Thank you for your help!
P.S. Sorry if this has been asked before. I searched but could not find the answer.