Let's say I have a dataframe df and a list obj.
df<- data.frame(x=c(1, 2, 3, 4),
y=c(1, 2, 3, 4))
obj <- list(data.frame(z=c(0, 0, 0, 0),
a=c(0, 0, 0, 0)),
data.frame(b=c(0, 0, 0, 0)))
I create a function myFun that modifies one column in df and adds it to the list obj. How do I update both x and o in the global environment? In other words, how do I have the function update df and obj?
myFun <- function(x, o) {
x[1] <- x[,1]*2
o <- list(o, x[1])
}
myFun(df, obj)