Here is my function:
adjusted <- c()
Adjustment <- function(delta, length) {
adjusted <<- vector_1 + delta*(index <= length)
head(adjusted)
}
Here is a hard-coded example of what I would like to achieve:
adjusted <- c()
Adjustment <- function(delta, length, group = 1) {
adjusted <<- vector_1[1:100] + delta*(index <= length)
head(adjusted)
}
I would like to implement a parameter or a loop that performs the calculation over the corresponding range of vector_1 for the inputted group parameter value. For example, if I instead entered group =2 the function would look like:
adjusted <- c()
Adjustment <- function(delta, length, group = 2) {
adjusted <<- vector_1[101:200] + delta*(index <= length)
head(adjusted)
}
Actual question:
How would I achieve this?
I found that the dplyr package may be useful for this, but I haven't been successful in implementing it.
Any insight would be much appreciated!