I'm creating a function that takes two inputs: delta, and length. The function modifies an existing vector - let's call this vector base - by delta for 'length' specified elements.
I need to create a new vector, let's call it 'adjusted'. This vector, adjusted, needs to populate based on one condition: If the index value for the base vector is less than the length parameter specified in the function input, then I want to increase the base vector by delta for all elements less than length. All elements in the base vector greater than the specified length parameter are to remain the same as in base vector. Here is an example of my code: I have tried to implement the logic in two ways. 1. Using an ifelse because it allows for vectorized output. 2. Using an if else logic. adjusted <- vector() #initialize the vector. #Create a function. Adjustment <- function(delta, length) { ifelse((index < length), (adjusted <- base + delta), (adjusted <- base)) head(adjusted) } #Method 2. Adjustment <- function(delta, length) { if (index < length) { adjusted <- base + delta } else {adjusted <- base} head(adjusted) } Where I am experiencing trouble is with my newly created vector, adjusted, will not populate. I'm not quite sure what is happening - I am very new to R and any insight would be much appreciated. -- Sent from: http://r.789695.n4.nabble.com/datatable-help-f2315188.html _______________________________________________ datatable-help mailing list datatable-help@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help