Hello,
I'm trying to divide multiple vectors by a ratio in a for loop using the get function. Here is an example:
a <- c(1, 2)
b <- c(10,12)
u <- c("a", "b")
n <- length(u)
k <- 1.1
i <- 1
for (i in 1:n) {
get(u[i]) <- get(u[i])*k
}
I've used get for these types of things but it doesn't seem to work on the left.
This is the error:
Error in get(u[i]) <- get(u[i]) * k : could not find function "get<-"
How can I fix this?
I want to keep a and b as separate variables and not do some kind of split function. And this seemed like a logical way of solving it.
Thank you!!