Not only that you can use vector element in your calculations, you can use entire vectors in order to get series of results.
a <- c(1, 2, 3)
b <- c(10, 20, 30)
Keep in mind that you need to have two vectors of equal number of element in order for this to work.
In case that you want to multiply those two, result is going to be another vector that is going to hold values that are result of multiplication of elements of those two vectors per index. So in case of our two vectors, result is going to be 10, 40, 90.
You could also perform calculations like this (a*b)[2] - 10. This is going to get us second element of first vector, multiplied by second element of second vector, and then from that number 10 is going to be subtracted. So in our case, result is going to be 30.
Function paste is going to append string value to string element of a vector. So if you have vector like b <- c("a", "b") if you do something like a <- paste(b, "1" sep="_"), you are going to get result "a_1", "b_1". So function paste is going to add appending string to every element of vector a, and with optional argument sep, we are going to provide character that is going to separate appending and appended string.
You can also do some binary operations with function xor(a, TRUE) or a|b in case that our two arrays contain only bool values.
For video on YouTube, check the link below.
No comments:
Post a Comment