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, not global ones.

Duncan Murdoch


                 #Drop a variable name from a data frame

DropLikeSAS<- function(x,df) {

                                 df[[x]]<- NULL

                                 0

                                 }

DropLikeSAS("VarName", DataFrameName)


Try it. The column VarName will not be deleted from the data frame 
DataFrameName.


But

x<- "VarName"
DataFrameName[[x]]<- NULL

Works.



        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to