Hi all,
I’m having a bit of difficulty understanding this
scope business. I’ve tried going through the help and googling to no
avail. It is probably very simple for you S veterans out there.
What I would like to do is modify a column in a global data
frame from within a function. For example, the current code I have looks like
this and works as I want it to:
my.dataframe <- data.frame(state.x77,
row.names=state.abb)
my.dataframe$Income <-
new.values.from.some.calculation
I want to change it so it’s like this:
my.function <- function() {
my.dataframe$Income <-
new.values.from.some.calculation
}
When I call my.function, I get a message saying that I need
to assign my.dataframe locally before replacement. I tried using code like this
my.function <- function() {
assign("my.dataframe[,\"Income\"]",
new.values.from.some.calculation)
}
but it also didn’t work. I don’t get an error
message, but the Income column is not changed. The data I’m working with
is big, so it’s not efficient to pass it into the function, change it, then
return it.
thanks,
Felipe