I am new to R. So basically I have 2 questions:
- In C++ we can pass objects as references to be able to return multiple modified objects from a function. What is equivalent way to modify multiple objects inside a function? (for example,
a
andb
infyfunc
) - In below code, I thought since I have access to
b
insidemyfunc
, I could modify it. But apparently, it's a copy ofb
. Is there anyway to actually modifyb
insidemyfunc
?
a <- c(1,2,3) b <- c(4,5,6) myfunc <- function(a) { b <- b+1 cat(b) # prints: 5 6 7 a <- a+1 } a <- myfunc(a) a b # stil 4 5 6