Re: [R] dropping variables from a data frame inside a function

2012-06-22 Thread Duncan Murdoch
On 12-06-22 5:09 PM, Joseph Boyer wrote: Why doesn't this work? David gave you a solution that works. The answer to this question is that unlike SAS, R is a computing language that has an idea of variable scoping: when you modify the argument df in DropLikeSAS, you are making local changes

Re: [R] dropping variables from a data frame inside a function

2012-06-22 Thread R. Michael Weylandt
I think the OP might also be tripped up on the fact that R is pass-by-value so effects on df inside DropLikeSAS won't have impact outside the function's scope. The df inside of DropLikeSAS() is changed as expected, but that has no effect on the df outside that function. To the OP: There are ways t

Re: [R] dropping variables from a data frame inside a function

2012-06-22 Thread David Winsemius
On Jun 22, 2012, at 5:09 PM, Joseph Boyer wrote: DropLikeSAS <- function(x,df) { df[[x]] <- NULL 0 } DropLikeSAS("VarName", DataFrameName) Sorry for the blank message> > DropLikeSAS <- function(x

Re: [R] dropping variables from a data frame inside a function

2012-06-22 Thread David Winsemius
On Jun 22, 2012, at 5:09 PM, Joseph Boyer wrote: Why doesn't this work? #Drop a variable name from a data frame DropLikeSAS <- function(x,df) { df[[x]] <- NULL 0 } DropLikeSAS("VarN

[R] dropping variables from a data frame inside a function

2012-06-22 Thread Joseph Boyer
Why doesn't this work? #Drop a variable name from a data frame DropLikeSAS <- function(x,df) { df[[x]] <- NULL 0 } DropLikeSAS("VarName", DataFrameName) Try it. The column VarName